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
/** * Create a success element, and append the correct command name. * //from www .j a va 2 s . c o m * @param outDoc * the document for output xml * @param commandName * name of the successfully executed command * @return a <success><commmand name=$commandname /></success> Element */ public static Element createSuccess(Document outDoc, String commandName) { Element success = outDoc.createElement("success"); Element cmd = outDoc.createElement("command"); cmd.setAttribute("name", commandName); success.appendChild(cmd); Element parameter = outDoc.createElement("parameters"); success.appendChild(parameter); Element output = outDoc.createElement("output"); success.appendChild(output); return success; }
From source file:Main.java
public static void addAsFirstChild(Element element, Element newChild) { if (element.hasChildNodes()) { element.insertBefore(newChild, element.getChildNodes().item(0)); } else {//from ww w . j a v a 2 s . co m element.appendChild(newChild); } }
From source file:Main.java
private static Node addNodeWithText(final Document doc, final Element parent, String name, String text) { final Element child = doc.createElement(name); child.setTextContent(text);//ww w . j a v a2 s . c o m return parent.appendChild(child); }
From source file:Main.java
public static void appendNewCDATAElement(Document doc, Element targetElement, String elementName, String value) {//from w ww. j a v a 2 s .c o m if (value != null) { targetElement.appendChild(createCDATAElement(elementName, value, doc)); } }
From source file:Main.java
/** * Adds an {@link Element} child to the given element. * <p>//from ww w. j a v a 2 s. co m * If you only want to generate elements for a document that is to be * serialized, this method is fine. If, however, you want to manipulate * the document, you should probably use * {@link #addElementChildTo(Element,String,String)}. * * @param parent The {@link Element} to add the {@link Element} child to. * @param tagName The tag name of the new {@link Element} child. * @return Returns A new {@link Element} with its <code>nodeName</code> set * to <code>tagName</code>, and <code>localName</code>, <code>prefix</code>, * and <code>namespaceURI</code> set to <code>null</code>. * @see #addElementChildTo(Element,String,String) */ public static Element addElementChildTo(Element parent, String tagName) { final Document doc = parent.getOwnerDocument(); final Element child = doc.createElement(tagName); parent.appendChild(child); return child; }
From source file:Main.java
/** * Creates a DOM element/*from w w w . j a v a2s . c om*/ * @param parent parent DOM element * @param tagName element name * @return a DOM element */ public static Element createElement(Element parent, String tagName) { Document doc = parent.getOwnerDocument(); Element e = doc.createElement(tagName); parent.appendChild(e); return e; }
From source file:Main.java
/** * @param target/*w w w . j a va 2 s. co m*/ * @param node * @return */ public static Node copyNode(Element target, Node node) { Node n = node.cloneNode(true); Document targetDoc = target.getOwnerDocument(); targetDoc.adoptNode(n); target.appendChild(n); return node; }
From source file:Main.java
/** * Create an element with the specified name * * @param parent/*from w w w . j a va 2 s . co m*/ * @param tagName * @return */ public static Element createElement(Element parent, String tagName) { Document doc = parent.getOwnerDocument(); Element child = doc.createElement(tagName); parent.appendChild(child); return child; }
From source file:Main.java
/** * This is used to create a child node//from w w w . j av a2s .c om * * @param document * @param parent * @param childName * @param childContents */ public static void addChildElement(Document document, Element parent, String childName, String childContents) { Element childElement = document.createElement(childName); childElement.setTextContent(childContents); parent.appendChild(childElement); }
From source file:Main.java
/** * Returns a document with a HTML node containing a HEAD and BODY node. *//*from ww w.ja v a2 s . co m*/ public static Document createHtmlDocument() { Document document = createDocument(); Element root = document.createElement("html"); document.appendChild(root); Element head = document.createElement("head"); root.appendChild(head); Element body = document.createElement("body"); root.appendChild(body); return document; }