Example usage for org.w3c.dom Attr setNodeValue

List of usage examples for org.w3c.dom Attr setNodeValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr setNodeValue.

Prototype

public void setNodeValue(String nodeValue) throws DOMException;

Source Link

Document

The value of this node, depending on its type; see the table above.

Usage

From source file:Main.java

/**
 * Adds an attribute to the specified document element.
 * @param doc the document./*from  www  .  ja v  a 2 s.c  o m*/
 * @param parent the parent element.
 * @param name the attribute name.
 * @param value the attribute value.
 * @return the attribute.
 */
public static Attr addAttribute(final Document doc, final Element parent, final String name,
        final String value) {
    Attr attr = doc.createAttribute(name);
    attr.setNodeValue(value);
    parent.setAttributeNode(attr);
    return attr;
}

From source file:Main.java

public static void addAttribute(Document doc, Node parentNode, String name, String content) {
    Attr attNode = doc.createAttribute(name);
    attNode.setNodeValue(content);
    parentNode.getAttributes().setNamedItem(attNode);
}

From source file:Main.java

public static void addAttribute(Document document, Node node, String attName, String attValue) {
    Attr attr = document.createAttribute(attName);
    attr.setNodeValue(removeXMLInvalidChars(attValue));
    node.getAttributes().setNamedItem(attr);
}

From source file:Main.java

public static void addAttribute(Document xmlDoc, Node node, String attrName, String attrValue) {
    Attr newAtt = xmlDoc.createAttribute(attrName);
    newAtt.setNodeValue(attrValue);
    NamedNodeMap attrs = node.getAttributes();
    attrs.setNamedItem(newAtt);/*  www  .java 2 s .c o  m*/
}

From source file:Main.java

/**
 * @param sampleNode/*from w  w  w .j  a  v  a 2  s . c  o m*/
 */
public static void tTestSetSampleAsReference(Node sampleNode) {
    Attr attr = sampleNode.getOwnerDocument().createAttribute("ttest");
    attr.setNodeValue("reference");
    Element e = (Element) sampleNode;
    e.setAttributeNode(attr);
}

From source file:Main.java

public static Node addAttribute(Node pNode, String attrName, String attrValue) {
    Node attributeNode = null;/*from w ww.ja v a2s  .co  m*/
    try {
        Attr _attr = pNode.getOwnerDocument().createAttribute(attrName);
        _attr.setNodeValue(attrValue);

        attributeNode = pNode.getAttributes().setNamedItem(_attr);

    } catch (Exception e) {
        attributeNode = null;
    }

    return attributeNode;
}

From source file:Main.java

/**
 * Get the attribute.//w w  w . j  a  v a2  s. co  m
 * 
 * @param attributeName
 *          the attribute name
 * @param attributeValue
 *          the attribute value
 * @param doc
 *          the document
 * @return the attribute
 */
private static Attr getAttribute(String attributeName, String attributeValue, Document doc) {
    Attr attr = doc.createAttribute(attributeName);
    attr.setNodeValue(attributeValue);
    return attr;
}

From source file:Main.java

public static void tTestSetSampleSignificane(Node sampleNode, boolean different) {
    Attr attr = sampleNode.getOwnerDocument().createAttribute("ttest");
    if (different)
        attr.setNodeValue("H1");
    else//from w w w.  ja va2 s .co  m
        attr.setNodeValue("H0");
    // System.out.println(attr.getNodeValue());
    Element e = (Element) sampleNode;
    e.setAttributeNode(attr);
    e.removeAttribute("ttest-level");
}

From source file:Main.java

public static void writeOutAttributesForNode(Map<?, ?> attributes, Node node) {
    if (attributes != null) {
        // Add attributes
        for (Iterator<?> i = attributes.keySet().iterator(); i.hasNext();) {
            Object key = i.next();
            Object value = attributes.get(key);
            if ((key != null) && (value != null)) {
                Attr attNode = node.getOwnerDocument().createAttribute(key.toString());
                attNode.setNodeValue(value.toString());
                node.getAttributes().setNamedItem(attNode);
            }//  w w w .  j  av a  2 s.  c o  m
        }
    }
}

From source file:Main.java

public static void writeOutAttributesForNode(String[][] attributes, Node node) {
    if (attributes != null) {
        // Add attributes
        for (int n = 0; n < attributes.length; n++) {
            String key = attributes[n][0];
            String value = attributes[n][1];
            if ((key != null) && (value != null)) {
                Attr attNode = node.getOwnerDocument().createAttribute(key.toString());
                attNode.setNodeValue(value.toString());
                node.getAttributes().setNamedItem(attNode);
            }//from   w  w  w. j  a  v  a  2s .co  m
        }
    }
}