Java Utililty Methods XML Attribute Add

List of utility methods to do XML Attribute Add

Description

The list of methods to do XML Attribute Add are organized into topic(s).

Method

voidaddAttribute(final Node node, final Attr attribute)
add Attribute
if (node != null) {
    node.getAttributes().setNamedItem(attribute);
AttraddAttribute(Node parent, String name, String value)
add Attribute
if (value == null)
    return null;
Attr node = parent.getOwnerDocument().createAttribute(name);
try {
    node.setValue(value);
    parent.getAttributes().setNamedItem(node);
} catch (Exception e) {
    System.out.println("Problem rewriting " + parent.getNodeName() + "." + name + "='" + node.getValue()
...
NodeaddAttribute(Node pNode, String attrName, String attrValue)
add Attribute
Node attributeNode = null;
try {
    Attr _attr = pNode.getOwnerDocument().createAttribute(attrName);
    _attr.setNodeValue(attrValue);
    attributeNode = pNode.getAttributes().setNamedItem(_attr);
} catch (Exception e) {
    attributeNode = null;
return attributeNode;
ElementaddAttributes(Element element, String[][] attributes)
add Attributes
for (String[] attr : attributes) {
    element.setAttribute(attr[0], attr[1]);
return element;
StringaddAttributeToXPathExpression(Node nodeAttr, String xpathExpression, String and)
add Attribute To X Path Expression
String value = nodeAttr.getNodeValue();
xpathExpression = xpathExpression + and + "@" + nodeAttr.getNodeName() + "='" + value + "'";
return xpathExpression;
NodeaddDomAttr(Document doc, String tagName, String tagNamespaceURI, String attrName, String attrValue)
Adds the attribute to each node in the Document with the given name.
Document newDoc = null;
try {
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
            "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    newDoc = db.newDocument();
...
voidaddDoubleAttributeAsInteger(Element element, String attName, double value)
add Double Attribute As Integer
element.setAttribute(attName, Long.toString(Math.round(value)));
ElementaddElement(Node parent, String name, Attr[] attrs)
add Element
Element element;
if (parent instanceof Document) {
    element = ((Document) parent).createElement(name);
} else {
    element = parent.getOwnerDocument().createElement(name);
if (attrs != null && attrs.length > 0) {
    for (Attr attr : attrs) {
...
NodeaddElementAndAttributes(Node parent, String name, String[] atts)
add Element And Attributes
Node n = addElement(parent, name);
for (int i = 0; i < atts.length; i += 2)
    addAttribute(n, atts[i], atts[i + 1]);
return n;
voidaddNewElementWithAttribute(Node node, String elementName, String elementValue, String attrName, String attrValue)
add New Element With Attribute
Document xmlDoc = node.getOwnerDocument();
addNewElementWithAttribute(xmlDoc, node, elementName, elementValue, attrName, attrValue);