List of utility methods to do XML Element Create
Element | createElement(String tag, String textContent, Document xml) Creates and returns an element with the specified tag and text content Element element = xml.createElement(tag);
element.setTextContent(textContent);
return element;
|
Element | createElement(String tagName, String text, Document doc) create Element Element elem = doc.createElement(tagName); if ((text != null) && !text.equals("")) elem.appendChild(doc.createTextNode(text)); return elem; |
Element | createElementAndText(Element parent, String elementName, String text) create Element And Text if (text == null) { throw new NullPointerException("null text"); Element el = parent.getOwnerDocument().createElement(elementName); parent.appendChild(el); Text txt = el.getOwnerDocument().createTextNode(text); el.appendChild(txt); return el; ... |
Element | createElementInSameNamespace(Element parent, String localName) create a new element in the same namespace String qName = localName; String prefix = parent.getPrefix(); if (prefix != null && prefix.length() > 0) { qName = prefix + ":" + localName; String nsUri = parent.getNamespaceURI(); return parent.getOwnerDocument().createElementNS(nsUri, qName); |
Element | createElementInTempDocument(String name, String prefix, String namespaceURI) create Element In Temp Document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); try { Document doc = dbf.newDocumentBuilder().newDocument(); return createElement(doc, name, prefix, namespaceURI); } catch (ParserConfigurationException ex) { return null; |
Element | createElementLn(Document d, String name, String value, boolean isCDATA) Creates a DOM element node with the given name and contents. Element e = createElement(d, name); if (isCDATA) { e.appendChild(createTextLn(d)); e.appendChild(createCDATA(d, value)); e.appendChild(createTextLn(d)); } else { e.appendChild(createTextLn(d, "\n" + value)); return e; |
Map | createElementMapping(final Document doc1, final Document doc2) Creates the element mapping for the specified documents. final Map<Node, Node> mapping = new HashMap<>(); createElementMappingForNodes(doc1.getDocumentElement(), doc2.getDocumentElement(), mapping); return mapping; |
void | createElementMappingForNodes(final Node n1, final Node n2, final Map Creates the element mapping for the specified nodes and all their child nodes. mapping.put(n1, n2); final NodeList childNodes1 = n1.getChildNodes(); final NodeList childNodes2 = n2.getChildNodes(); final int count = Math.min(childNodes1.getLength(), childNodes2.getLength()); for (int i = 0; i < count; i++) { createElementMappingForNodes(childNodes1.item(i), childNodes2.item(i), mapping); |
Element | createElementNS(Document doc, String namespaceURI, String prefix, String nodeName) Creates and returns a new XML element node with the given name and namespace URI. String fullName = (prefix == null) ? nodeName : prefix + ":" + nodeName; Element e = doc.createElementNS(namespaceURI, fullName); if (printXMLNamespaces) { String attrName = (prefix == null) ? "xmlns" : "xmlns:" + prefix; e.setAttribute(attrName, namespaceURI); return e; |
Element | createElementNS(Document root, String namespaceURI, String qualifiedName) create Element NS return root.createElementNS(namespaceURI, qualifiedName);
|