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

/**
 * Creates the text.//from   w  w  w . ja va  2s .c o  m
 *
 * @param parent
 *          the parent
 * @param text
 *          the text
 *
 * @return the text
 */
public static Text createText(final Node parent, final String text) {
    final Text child = parent.getOwnerDocument().createTextNode(text);
    parent.appendChild(child);
    return child;
}

From source file:Main.java

public static Element createNewCDATAElement(Node elem, String tag, String value) {
    Document doc = elem.getOwnerDocument();
    Element res = doc.createElement(tag);
    CDATASection cdata = doc.createCDATASection(value);
    res.appendChild(cdata);//from w ww . ja va 2s. c o m
    elem.appendChild(res);
    return res;
}

From source file:Main.java

public static Document getDocument(Node node) {
    return (Document) (node instanceof Document ? node : node.getOwnerDocument());
}

From source file:Main.java

/**
 * This method creates a new textnode with the passed on value.
 *
 * @param  sValue   The value for the new textnode.
 * @param  nParent  The parent node.//www.j  ava2s  . c o m
 */
public static void createText(String sValue, Node nParent) {
    if (nParent != null) {
        Document dDoc = nParent.getOwnerDocument();
        Node nTemp = dDoc.createTextNode(sValue);
        nParent.appendChild(nTemp);
    }
}

From source file:Main.java

public static void setTTestSetSampleSignificane(Node sampleNode, boolean different, double level) {
    Attr attr = sampleNode.getOwnerDocument().createAttribute("ttest");
    Attr attrLevel = sampleNode.getOwnerDocument().createAttribute("ttest-level");
    if (different)
        attr.setNodeValue("H1");
    else/*from  www.  j a  va 2s  .  c  om*/
        attr.setNodeValue("H0");
    // System.out.println(attr.getNodeValue());
    attrLevel.setNodeValue(level + "");
    Element e = (Element) sampleNode;
    e.setAttributeNode(attr);
    e.setAttributeNode(attrLevel);
}

From source file:Main.java

/**
 * Creates and returns a new XML node with the specified name, as a child
 * of the given parent//from w w w  .j  ava 2s  . c o  m
 * Returns null if the child could not be created
 */
public static Node createChild(Node parent, String name) {
    // Create the node
    Node child = parent.getOwnerDocument().createElement(name);
    if (child != null) {
        // Add it to the document
        parent.appendChild(child);
    }

    return child;
}

From source file:Main.java

/**
 * Creates the element.//  w w w . ja v a 2  s.co m
 *
 * @param parent
 *          the parent
 * @param nodeName
 *          the node name
 *
 * @return the element
 */
public static Element createElement(final Node parent, final String nodeName) {
    final Element child = parent.getOwnerDocument().createElement(nodeName);
    parent.appendChild(child);
    return child;
}

From source file:Main.java

public static void appendChild(Node parent, Node... nodes) {
    Document doc = parent.getOwnerDocument();
    for (Node node : nodes) {
        if (node.getOwnerDocument() != doc) {
            parent.appendChild(doc.importNode(node, true));
        } else {/*ww  w  .j  a v a 2 s.com*/
            parent.appendChild(node);
        }
    }
}

From source file:Main.java

public static Element addElement(Node parent, String name) {
    Element node;// w w  w  .  ja va 2  s.com
    if (parent.getOwnerDocument() != null) {
        node = parent.getOwnerDocument().createElement(name);
    } else if (parent instanceof Document) {
        node = ((Document) parent).createElement(name);
    } else {
        return null;
    }
    parent.appendChild(node);
    return node;
}

From source file:Main.java

public static void addAttribute(Node node, String attrName, String attrValue) {
    Document xmlDoc = node.getOwnerDocument();
    addAttribute(xmlDoc, node, attrName, attrValue);
}