List of usage examples for org.w3c.dom Document createElement
public Element createElement(String tagName) throws DOMException;
From source file:net.sf.jabref.exporter.OOCalcDatabase.java
private static void addTableCell(Document doc, Element parent, String content) { Element cell = doc.createElement("table:table-cell"); Element text = doc.createElement("text:p"); Text textNode = doc.createTextNode(content); text.appendChild(textNode);//from ww w . j av a 2 s. co m //text.setTextContent(content); cell.appendChild(text); parent.appendChild(cell); }
From source file:com.twentyn.patentExtractor.Util.java
public static Document nodeToDocument(DocumentBuilder docBuilder, String documentContainer, Node n) { /* With help from://from w ww . j a v a 2s . com * http://examples.javacodegeeks.com/core-java/xml/dom/copy-nodes-subtree-from-one-dom-document-to-another/ */ org.w3c.dom.Document newDoc = docBuilder.newDocument(); Element rootElement = newDoc.createElement(documentContainer); Node newNode = newDoc.importNode(n, true); rootElement.appendChild(newNode); newDoc.appendChild(rootElement); return newDoc; }
From source file:Main.java
public static Node addChildNode(Node pNode, String name, String value) { Document _doc = null; if (pNode.getNodeType() == Node.DOCUMENT_NODE) { _doc = (Document) pNode;/*from ww w . j a va2 s . c o m*/ } else { _doc = pNode.getOwnerDocument(); } Element _ele = _doc.createElement(name); Node _node = _doc.createTextNode(value); _ele.appendChild(_node); return pNode.appendChild(_ele); }
From source file:Main.java
/** * Find or create a child element with the given name * @param element/*from w ww . j av a 2s . c o m*/ * @param name * @return new or existing element */ public static Element findOrCreateChildElement(Document document, Element element, String name) { Element[] elements = getChildElementsNamed(element, name); Element kid; if (elements.length > 0) { kid = elements[0]; } else { kid = document.createElement(name); element.appendChild(kid); } return kid; }
From source file:Main.java
/** * adds an Element with two attributs to a DOM-tree. * //from w w w .j a v a 2 s. c om * @param document * Document: the DOM-tree to add to * @param father * Element: the new element will be inserted directly under this * Element in the tree * @param name * String: the name of the new element * @param attOneName * String: the name of the 1st attribut * @param attOneValue * String: the value of the 1st attribut * @param attTwoName * String: the name of the 2nd attribut * @param attTwoValue * String: the value of the 2nd attribut */ public static void addElement(Document document, Element father, String name, String attOneName, String attOneValue, String attTwoName, String attTwoValue) { Element element = document.createElement(name); element.setAttribute(attOneName, attOneValue); element.setAttribute(attTwoName, attTwoValue); father.appendChild(element); }
From source file:Main.java
public static Document CreateCustomerFile(JFrame mainFrame) { Document CustomerDoc = null; try {// w w w.j av a 2 s .c o m DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance(); DocumentBuilder Build = Factory.newDocumentBuilder(); CustomerDoc = Build.newDocument(); Element rootElem = CustomerDoc.createElement("Customers"); CustomerDoc.appendChild(rootElem); } catch (ParserConfigurationException ex) { System.out.println(ex.getMessage()); JOptionPane.showMessageDialog(mainFrame, "There Was an Error Saving The File. Please Restart the Application."); System.exit(1); } return CustomerDoc; }
From source file:com.msopentech.odatajclient.engine.data.atom.AtomSerializer.java
private static Element entry(final AtomEntry entry) throws ParserConfigurationException { final DocumentBuilder builder = ODataConstants.DOC_BUILDER_FACTORY.newDocumentBuilder(); final Document doc = builder.newDocument(); final Element entryElem = doc.createElement(ODataConstants.ATOM_ELEM_ENTRY); entryElem.setAttribute(XMLConstants.XMLNS_ATTRIBUTE, ODataConstants.NS_ATOM); entryElem.setAttribute(ODataConstants.XMLNS_METADATA, ODataConstants.NS_METADATA); entryElem.setAttribute(ODataConstants.XMLNS_DATASERVICES, ODataConstants.NS_DATASERVICES); entryElem.setAttribute(ODataConstants.XMLNS_GML, ODataConstants.NS_GML); entryElem.setAttribute(ODataConstants.XMLNS_GEORSS, ODataConstants.NS_GEORSS); if (entry.getBaseURI() != null) { entryElem.setAttribute(ODataConstants.ATTR_XMLBASE, entry.getBaseURI().toASCIIString()); }/* w ww .j a v a 2 s . c o m*/ doc.appendChild(entryElem); final Element category = doc.createElement(ODataConstants.ATOM_ELEM_CATEGORY); category.setAttribute(ODataConstants.ATOM_ATTR_TERM, entry.getType()); category.setAttribute(ODataConstants.ATOM_ATTR_SCHEME, ODataConstants.ATOM_CATEGORY_SCHEME); entryElem.appendChild(category); if (StringUtils.isNotBlank(entry.getTitle())) { final Element title = doc.createElement(ODataConstants.ATOM_ELEM_TITLE); title.appendChild(doc.createTextNode(entry.getTitle())); entryElem.appendChild(title); } if (StringUtils.isNotBlank(entry.getSummary())) { final Element summary = doc.createElement(ODataConstants.ATOM_ELEM_SUMMARY); summary.appendChild(doc.createTextNode(entry.getSummary())); entryElem.appendChild(summary); } setLinks(entryElem, entry.getAssociationLinks()); setLinks(entryElem, entry.getNavigationLinks()); setLinks(entryElem, entry.getMediaEditLinks()); final Element content = doc.createElement(ODataConstants.ATOM_ELEM_CONTENT); if (entry.isMediaEntry()) { if (StringUtils.isNotBlank(entry.getMediaContentType())) { content.setAttribute(ODataConstants.ATTR_TYPE, entry.getMediaContentType()); } if (StringUtils.isNotBlank(entry.getMediaContentSource())) { content.setAttribute(ODataConstants.ATOM_ATTR_SRC, entry.getMediaContentSource()); } if (content.getAttributes().getLength() > 0) { entryElem.appendChild(content); } if (entry.getMediaEntryProperties() != null) { entryElem.appendChild(doc.importNode(entry.getMediaEntryProperties(), true)); } } else { content.setAttribute(ODataConstants.ATTR_TYPE, ContentType.APPLICATION_XML.getMimeType()); if (entry.getContent() != null) { content.appendChild(doc.importNode(entry.getContent(), true)); } entryElem.appendChild(content); } return entryElem; }
From source file:Main.java
/** * Add an element to a parent element with its value. * @param doc DOM document object//from w w w.jav a 2s . c om * @param parentElement parent element * @param elementName name of the element * @param value text of the element */ public static void addTagValue(final Document doc, final Element parentElement, final String elementName, final String value) { if (doc == null || parentElement == null || elementName == null || value == null) { return; } Element child = doc.createElement(elementName); parentElement.appendChild(child); child.appendChild(doc.createTextNode(value)); }
From source file:Main.java
public static Element createElement(String tag) throws Exception { DocumentBuilderFactory oDOMFactory = null; DocumentBuilder oDOMBuilder = null; org.w3c.dom.Document oDOMDocument = null; oDOMFactory = DocumentBuilderFactory.newInstance(); // oDOMFactory.setNamespaceAware(true); oDOMBuilder = oDOMFactory.newDocumentBuilder(); oDOMDocument = oDOMBuilder.newDocument(); Element oElement = oDOMDocument.createElement(tag); return oElement; }
From source file:Main.java
public static void append(Document source, String path, Document target) throws XPathExpressionException, IOException { Element e = target.getDocumentElement(); if (e == null) { e = target.createElement("result"); target.appendChild(e);/* w w w .ja v a2s .c o m*/ } append(source.getDocumentElement(), path, e); }