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
/** * This method is used to insert a new tag below the tag specified by * <code>appendTo</code> parameter. * //from w w w.j av a 2s . c om * @param d * the <code>Document</code> object to which a new tag is to be * inserted. * @param appendTo * the tag below which a new tag needs to be inserted. * @param tagName * the name of new tag * @param tagValue * the value of new tag */ public static Element insertNewTagBelow(Document d, String appendTo, String tagName, String tagValue) { Node element = d.getElementsByTagName(appendTo).item(0); if (element == null) { element = d.createElement(appendTo); } Element newElement = d.createElement(tagName); element.appendChild(newElement); newElement.appendChild(d.createTextNode(tagValue)); return newElement; }
From source file:Main.java
/** * Add the child node to parent/*w ww .j a v a2 s .c o m*/ * * @param parent * @param child */ public static void addElement(Element parent, Element child) { parent.appendChild(child); }
From source file:Main.java
/** *//*from w w w .j av a 2 s . c o m*/ public static void appendComment(Element element, String comment) { Node commentNode = element.getOwnerDocument().createComment(comment); element.appendChild(commentNode); }
From source file:Main.java
/** * DOM Level 2 compliant method for adding text to an element * //from ww w.j a v a2 s . c o m * @param e * element to which text should be added * @param contents * new text to be added * @return */ public static Text appendTextNode(Element e, String contents) { Text textNode = e.getOwnerDocument().createTextNode(contents); e.appendChild(textNode); return textNode; }
From source file:Main.java
private static void makeNamelist(Document doc) { String names = null;//from w ww. j a v a 2 s .com Element root = doc.getDocumentElement(); NodeList nameElements = root.getElementsByTagName("name"); for (int i = 0; i < nameElements.getLength(); i++) { Element name = (Element) nameElements.item(i); Text nametext = (Text) name.getFirstChild(); if (names == null) { names = nametext.getData(); } else { names += ", " + nametext.getData(); } } Element namelist = doc.createElement("names"); Text namelisttext = doc.createTextNode(names); namelist.appendChild(namelisttext); root.insertBefore(namelist, root.getFirstChild()); }
From source file:Main.java
public static synchronized void appedIndent(Element e, int indent) { Document doc = e.getOwnerDocument(); if (indent == 0) { e.appendChild(doc.createTextNode("\n")); }/*from w w w . jav a2 s .c om*/ for (int i = 0; i < indent; i++) { if (i == 0) { e.appendChild(doc.createTextNode("\n\t")); } else { e.appendChild(doc.createTextNode("\t")); } } }
From source file:Main.java
private static Element makePersonNode(Document doc, String name, String phone) { Element nameNode = doc.createElement("name"); Text nametextNode = doc.createTextNode(name); nameNode.appendChild(nametextNode); Element phoneNode = doc.createElement("phone"); Text phonetextNode = doc.createTextNode(phone); phoneNode.appendChild(phonetextNode); Element personNode = doc.createElement("person"); personNode.appendChild(nameNode);/*ww w. j a v a2 s .c o m*/ personNode.appendChild(phoneNode); return (personNode); }
From source file:Main.java
/** * Append the given list of children Elements to the given Element. * * @param element The parent element.//from ww w .j av a 2 s . c om * @param children The list of children. */ public static void addChildren(Element element, List children) { for (int i = 0; i < children.size(); i++) { element.appendChild((Element) children.get(i)); } }
From source file:Main.java
public static Element createCDATAElement(String name, Object value, Document doc) { Element element = doc.createElement(name); element.appendChild(doc.createCDATASection(value.toString())); return element; }
From source file:Main.java
public static Element createChild(Document paramDocument, Element paramElement, String paramString) { Element localElement = paramDocument.createElement(paramString); paramElement.appendChild(localElement); return localElement; }