List of usage examples for org.w3c.dom Element appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:Main.java
public static void append(Document doc, String name, String phone, String email) { Element personNode = doc.createElement("person"); Element nameNode = doc.createElement("name"); personNode.appendChild(nameNode); Text nametextNode = doc.createTextNode(name); nameNode.appendChild(nametextNode);//from www .ja va 2 s. c om Element phoneNode = doc.createElement("phone"); personNode.appendChild(phoneNode); Text phonetextNode = doc.createTextNode(phone); phoneNode.appendChild(phonetextNode); Element emailNode = doc.createElement("email"); personNode.appendChild(emailNode); Text emailtextNode = doc.createTextNode(email); emailNode.appendChild(emailtextNode); Element root = doc.getDocumentElement(); root.appendChild(personNode); }
From source file:Main.java
private static void addTextContent(Document doc, Element root, String param, String value) { Element ele = doc.createElement(param); ele.setTextContent(value);//from w w w. jav a 2 s . c om root.appendChild(ele); }
From source file:Main.java
public static Element writeBooleanElement(Document document, String name, boolean value, Element parentElement) {//w w w. j a va2 s . c o m Element element = document.createElement(name); Text text = document.createTextNode(Boolean.toString(value)); element.appendChild(text); parentElement.appendChild(element); return element; }
From source file:Main.java
public static Element createChildElement(String tagName, Element parentElement) { Element result = parentElement.getOwnerDocument().createElement(tagName); parentElement.appendChild(result); return result; }
From source file:Main.java
public static Element addElement(final Element parent, final String name) { final Element ele = parent.getOwnerDocument().createElement(name); parent.appendChild(ele); return ele;//from w ww .j a v a 2 s . c om }
From source file:Main.java
/** * Creates an element representing {@code <tag>text</tag>} and appends it to {@code parent}. * * @param doc/*from w w w . j a va 2s . c o m*/ * The {@link Document} containing the {@link Element}. * @param parent * The {@link Node} to append the created {@link Element} to. * @param tag * The tag name of the created {@link Element}. * @param text * The content of the created {@link Element}. * @return the {@link Element} created. */ public static Element appendField(Document doc, Element parent, String tag, String text) { Element elem = createField(doc, tag, text); parent.appendChild(elem); return elem; }
From source file:Main.java
public static Document createXMLResult(String rootName, Map<String, String> map, Document d) { try {//from w w w .j a va2s . c om Element r = d.createElement(rootName); d.appendChild(r); for (String elementName : map.keySet()) { Element eltName = d.createElement(elementName); eltName.appendChild(d.createTextNode(map.get(elementName))); r.appendChild(eltName); } d.normalizeDocument(); return d; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public static void encodeString(Document doc, Element parent, String str, String namespaceURI, String qualifiedName) {/*from w w w . j a va 2 s. c om*/ if (str != null) { Element elm = doc.createElementNS(namespaceURI, qualifiedName); Text strVal = doc.createTextNode(str); elm.appendChild(strVal); parent.appendChild(elm); } }
From source file:Main.java
public static Element appendElement(Element parent, String tagName) { Element child = parent.getOwnerDocument().createElement(tagName); parent.appendChild(child); return child; }
From source file:Main.java
License:asdf
public static void replacePerson(Document doc, String name, String phone, String email) { Element newPersonNode = doc.createElement("person"); Element nameNode = doc.createElement("name"); newPersonNode.appendChild(nameNode); Text nametextNode = doc.createTextNode(name); nameNode.appendChild(nametextNode);/*from w w w.java 2s. com*/ Element phoneNode = doc.createElement("phone"); newPersonNode.appendChild(phoneNode); Text phonetextNode = doc.createTextNode(phone); phoneNode.appendChild(phonetextNode); Element emailNode = doc.createElement("email"); newPersonNode.appendChild(emailNode); Text emailtextNode = doc.createTextNode(email); emailNode.appendChild(emailtextNode); Element root = doc.getDocumentElement(); Element oldPersonNode = (Element) root.getFirstChild(); root.replaceChild(newPersonNode, oldPersonNode); }