List of usage examples for org.w3c.dom Document 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 cloneAndAppend(Document document, Node node) { node = node.cloneNode(true);/*from ww w.ja va 2s .c o m*/ document.adoptNode(node); document.appendChild(node); }
From source file:Main.java
/** * Start a new XML Document./*from www. j a v a 2 s . c om*/ * @param rootName The name of the Document root Element (created here) * @return the Document * @throws DomException */ public static Document createXmlDocument(String rootName) throws Exception { DocumentBuilderFactory factory; factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(false); Document document = factory.newDocumentBuilder().newDocument(); Element root = document.createElement(rootName); document.appendChild(root); return document; }
From source file:Main.java
/** * Creates the root tag node./*from w ww. ja v a 2s. c o m*/ * * @param baseDocument * the base document * @param rootTagName * the root tag name * @return the element */ public static Element createRootTagNode(Document baseDocument, String rootTagName) { Element newNode = baseDocument.createElement(rootTagName); baseDocument.appendChild(newNode); return newNode; }
From source file:Main.java
public static Document newDocumentFromElement(Element toBeImported) throws ParserConfigurationException { Document doc = newDocument(); Element importedNode = (Element) doc.importNode(toBeImported, true); doc.appendChild(importedNode); return doc;/*from ww w . jav a2 s . c om*/ }
From source file:Main.java
static public Document createDefaultMessage(String messagetype) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentbuilder = null; try {/* ww w . j a v a 2 s .c o m*/ documentbuilder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } Document doc = documentbuilder.newDocument(); Element root = doc.createElement("message"); doc.appendChild(root); long timestamp = System.currentTimeMillis(); root.setAttribute("timestamp", Long.toString(timestamp)); root.setAttribute("type", messagetype); return doc; }
From source file:Main.java
static public synchronized Element createDocument(String rootElemName) { // create document Document doc = createDocument(); Element root = doc.createElement(rootElemName); doc.appendChild(root); return root;//from w w w . j av a2 s . co m }
From source file:Main.java
/** * @param target/*from ww w. jav a2s. c o m*/ * @param node * @return * @throws Exception */ public static Document copyDocument(Document document) throws Exception { Node n = document.getDocumentElement().cloneNode(true); Document result = newDocument(); result.adoptNode(n); result.appendChild(n); return result; }
From source file:Main.java
public static void edit(Document document) { String docNS = "http://www.my-company.com"; Element order = document.createElementNS(docNS, "order"); document.appendChild(order); order.setAttribute("xmlns", docNS); }
From source file:Main.java
/** Creates a new DOM. */ public static Document createDocument(final String rootName) { if (docBuilder == null) { try {/*from ww w . ja v a2s .c om*/ docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (final ParserConfigurationException exc) { exc.printStackTrace(); return null; } } final Document doc = docBuilder.newDocument(); if (rootName != null) doc.appendChild(doc.createElement(rootName)); return doc; }
From source file:Main.java
public static synchronized void createIdStorage() throws ParserConfigurationException, TransformerException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement(IDS); doc.appendChild(rootElement); Transformer transformer = getTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(ID_STORAGE_LOCATION)); transformer.transform(source, result); }