Java Utililty Methods XML Node Name

List of utility methods to do XML Node Name

Description

The list of methods to do XML Node Name are organized into topic(s).

Method

NodegetNode(Node node, String nodeName)
get Node
if (node.getNodeType() == Node.ELEMENT_NODE) {
    Element el = (Element) node;
    NodeList nodeList = el.getElementsByTagName(nodeName);
    if (nodeList.getLength() > 0) {
        return nodeList.item(0);
return null;
...
NodegetNode(Node node, String nodeName)
get Node
List<Node> childList = getChildNodesByName(node, nodeName);
if (childList.size() > 0) {
    return childList.get(0);
} else {
    return null;
OptionalgetNodeContent(Node item, String nodeName)
Gets the content of a subnode.
if (item.getNodeType() != Node.ELEMENT_NODE) {
    return Optional.empty();
NodeList metadata = ((Element) item).getElementsByTagName(nodeName);
if (metadata.getLength() == 1) {
    return Optional.ofNullable(metadata.item(0).getTextContent());
} else {
    return Optional.empty();
...
StringgetNodeContent(Node n, String nodename)
get Node Content
Node r = getNode(n, nodename);
if (r != null)
    return r.getTextContent();
else
    return null;
StringgetNodeName(Node node)
Get the non qualified tag name
String localName = node.getLocalName();
if (localName != null) {
    return localName;
String name = node.getNodeName();
int idx = name.indexOf(":");
if (idx >= 0) {
    name = name.substring(idx + 1);
...
StringgetNodeName(Node node)
get Node Name
if (node == null) {
    System.out.println("node is null");
    return "";
String name = node.getNodeName();
if (name == null) {
    System.out.println("name is null");
    return "";
...
StringgetNodeName(Node node)
get Node Name
String name = node.getLocalName();
if (name == null)
    name = node.getNodeName();
return name;
StringgetNodeName(Node node)
get Node Name
String name = "";
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node curNode = nodeList.item(i);
    if ("name".equalsIgnoreCase(curNode.getNodeName())) {
        name = curNode.getTextContent().replace("\"", "");
        break;
return name;
StringgetNodeName(Node node)
get Node Name
String name = node.getNamespaceURI() != null ? node.getLocalName() : node.getNodeName();
if (name.contains(":")) { 
    String[] parts = name.split(":"); 
    name = parts[parts.length - 1];
return name;
StringgetNodeNameIgnorePrefix(Node node)
get node name without any prefix
if (node == null)
    return null;
String nodeName = node.getNodeName();
if (nodeName.contains(":")) {
    nodeName = nodeName.split(":")[1];
return nodeName;