Java XML Attribute from Node getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty)

Here you can find the source of getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty)

Description

get String Attribute Optional

License

Apache License

Declaration

public static String getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static String getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty) {
        NamedNodeMap attributes = node.getAttributes();
        Node value = attributes.getNamedItem(attributeName);
        if (value == null) {
            return valueIfEmpty;
        }//from w w  w. ja v  a 2 s . c om
        String text = value.getTextContent();
        if (text == null) {
            return valueIfEmpty;
        }
        return text;
    }
}

Related

  1. getNodeAttributeValue(Node node, String attrName)
  2. getNodeAttributeValueNS(Node node, String namespaceURI, String attrName)
  3. getNodeMap(NamedNodeMap artifactAttributes)
  4. getNodesByAttributeValue(Node node, String attrName, String attrValue)
  5. getNonEmptyAttribute(Element element, String namespace, String localName)
  6. getStringAttributeRequired(Node node, String attributeName)
  7. getValueForAttribute(Node currentNode, String attributeName)
  8. getXMLDate(Element e, String attrName)
  9. getXMLDate(Element e, String attrName)