Example usage for org.w3c.dom Node getOwnerDocument

List of usage examples for org.w3c.dom Node getOwnerDocument

Introduction

In this page you can find the example usage for org.w3c.dom Node getOwnerDocument.

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:Main.java

public static Element addChildElement(Node parent, String elementName) {
    Document ownerDocument = parent.getOwnerDocument();
    Objects.requireNonNull(ownerDocument, "nodes ownerDocument " + parent);
    Element element = ownerDocument.createElement(elementName);
    parent.appendChild(element);//from www .  j a  va  2  s . c o m
    return element;
}

From source file:Main.java

public static String XMLtoString(Node node) throws Exception {
    Document document = node.getOwnerDocument();
    DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
    LSSerializer serializer = domImplLS.createLSSerializer();
    serializer.getDomConfig().setParameter("xml-declaration", false);
    return serializer.writeToString(node);
}

From source file:Main.java

public static final void addNodeCDATAValue(Node node, String name, String value) {
    if (value != null) {
        Document doc = node.getOwnerDocument();
        Element e = doc.createElement(name);
        e.appendChild(doc.createCDATASection(value));
        node.appendChild(e);/* w  w  w .  ja  va 2  s .  c  om*/
    }
}

From source file:Main.java

public static Element createNewTextElement(Node elem, String tag, String value) {// throws Exception {
    Document doc = elem.getOwnerDocument();
    Element res = doc.createElement(tag);
    Text content = doc.createTextNode(value);
    res.appendChild(content);/*  www.  j  a  va  2s. com*/
    elem.appendChild(res);
    return res;
}

From source file:Main.java

public static final void addNodeValue(Node node, String name, String value) {
    if (value != null) {
        Document doc = node.getOwnerDocument();
        Element e = doc.createElement(name);
        e.appendChild(doc.createTextNode(value));
        node.appendChild(e);//w  w w.  j  ava 2  s  .  c om
    }
}

From source file:Main.java

/**
 * Add the specified attribute./*w w w .j  av  a2s .c o  m*/
 * @param e The node to add the attribute to.
 * @param name The name of the attribute.
 * @param value The value of the attribute.
 */
public static void addAttribute(final Node e, final String name, final String value) {
    final Attr attr = e.getOwnerDocument().createAttribute(name);
    attr.setValue(value);
    e.getAttributes().setNamedItem(attr);
}

From source file:Main.java

public static void nodeSubInsert(Element root, String table, String queryType, String queryValue) {
    Node find = getTag(root, table);
    Document doc = find.getOwnerDocument();

    Element type = doc.createElement(queryType);

    Text value = doc.createTextNode(queryValue);

    type.appendChild(value);/*w w w .j  ava2 s. c om*/
    find.appendChild(type);

    print(doc);

}

From source file:Main.java

/**
 * Gets the owner Document of a Node, possibly the node itself
 * //from   w w  w. ja v a 2 s.c o m
 * @param xml the Node for which to find the owner Document
 * @return the owner Document
 **/
public final static Document getOwnerDocument(final Node xml) {
    if (xml == null) {
        return null;
    }
    return xml.getOwnerDocument() == null ? (Document) xml : xml.getOwnerDocument();
}

From source file:Main.java

/**
 * Append node.//w ww  .j  a  v  a 2 s . c om
 *
 * @param baseNode
 *            the base node
 * @param tagName
 *            the tag name
 * @return the element
 */
public static Element appendNode(Node baseNode, String tagName) {
    Element newNode = baseNode.getOwnerDocument().createElement(tagName);
    baseNode.appendChild(newNode);
    return newNode;
}

From source file:Main.java

/**
 * add single element to a node. it doesn't check if an element exists with the same name.
 * @param contextNode is the node to which the element is added
 * @param elmName is the new element name, not XPath.
 * @return the new Element// w  w w .  j  av a  2 s.  com
 */
public static Element addSingleElement(Node contextNode, String elmName) throws Exception {
    Element elm = contextNode.getOwnerDocument().createElement(elmName);
    contextNode.appendChild(elm);
    return (elm);
}