XmlUtils { public static Element createElement(Node node, String name, String value, Map<String, Object> attributes) { Document doc = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument(); Element element = doc.createElement(name); element.setTextContent(value); addAttributes(element, attributes); return element; } private  XmlUtils(); static String toString(Node node); static String toString(Node node, boolean pretty); static void trimWhiteSpace(Node node); static Document toXmlDoc(String xml); static NodeList getNodeListByPath(Node node, String path); static String stripNameSpacePrefixes(String path); static Node getNodeByPath(Node node, String path, boolean create); static Node createNodeByPath(Document doc, String path); static String getTextValueByPath(Node node, String path); static void setByPath(Node doc, String path, String value); static void removeByPath(Document doc, String path); static void setByPath(Document doc, String path, Node in); static DocumentContext toJsonDoc(Node node); static int getChildElementCount(Node node); static Object toObject(Node node); static Object toObject(Node node, boolean removeNamespace); static Document fromMap(Map<String, Object> map); static Document fromObject(String name, Object o); static List<Element> fromObject(Document doc, String name, Object o); static Document newDocument(); static void addAttributes(Element element, Map<String, Object> map); static Element createElement(Node node, String name, String value, Map<String, Object> attributes); static Document toNewDocument(Node in); static Document toXmlDoc(Object o); static String toXml(Object o);  }
@Test public void testCreateElement() { Node node = XmlUtils.createElement(getDocument(), "foo", "bar", null); String result = XmlUtils.toString(node); assertEquals(result, "<foo>bar</foo>"); }