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

SetgetNodeNames(Set nodes)
get Node Names
Set<String> names = new HashSet<String>();
for (Node node : nodes) {
    names.add(node.getLocalName());
return names;
StringgetNodeNameWithNamespace(Node node)
get Node Name With Namespace
String name = node.getNodeName();
String ns = node.getNamespaceURI();
String prefix = (ns != null) ? node.lookupPrefix(ns) : null;
if ((prefix != null) && !name.startsWith(prefix + ":")) {
    name = prefix + ":" + name;
return name;
VectorgetNodes(Node iNode, String iNodeName)
This method returns an ordered list containing the desired nodes which is determined by the provided node name and namespace.
Logger.getLogger("org.adl.util.debug.validator").entering("DOMTreeUtility", "getNodes()");
Logger.getLogger("org.adl.util.debug.validator").info("Parent Node: " + iNode.getLocalName());
Logger.getLogger("org.adl.util.debug.validator").info("Node being searched for: " + iNodeName);
Vector result = new Vector();
if (iNode != null) {
    NodeList children = iNode.getChildNodes();
    if (children != null) {
        int numChildren = children.getLength();
...
ArrayListgetNodes(Node module, String interfaceName, String nodeName)
Gets all nodes of a module that are child of a given interface and have a specific name
Node iFace = getInterfaceNodeByName(interfaceName, module);
NodeList childs = iFace.getChildNodes();
ArrayList<Node> operations = new ArrayList<Node>();
Node child;
for (int i = 0; i < childs.getLength(); i++) {
    child = childs.item(i);
    if (child.getNodeName().equals(nodeName)) {
        operations.add(child);
...
IteratorgetNodes(Node node, String nodeName)
Searches parent node for matching child nodes.
ArrayList nodes = new ArrayList();
NodeList nl = node.getChildNodes();
int nll = nl.getLength();
for (int i = 0; i < nll; i++) {
    Node n = nl.item(i);
    if (n.getNodeName().equals(nodeName)) {
        nodes.add(n);
return nodes.iterator();
StringgetSimpleName(final Node node)
Gets XML node name.
return node.getLocalName() == null ? node.getNodeName().substring(node.getNodeName().indexOf(':') + 1)
        : node.getLocalName();
ListgetSubNodes(Node node, String subNodeName)
get Sub Nodes
List<Node> nodes = new ArrayList<Node>();
NodeList list_child = node.getChildNodes(); 
for (int ck = 0; ck < list_child.getLength(); ck++) {
    Node tmpNode = list_child.item(ck);
    if (tmpNode.getNodeName() != null && tmpNode.getNodeName().equals(subNodeName)) {
        nodes.add(tmpNode);
return nodes;
StringgetSubNodeValue(Node node, String nodeName, String subNodeName)
Searches parent node 2 levels deep and returns the first match node's value.
Node subNode = getNode(node, nodeName);
if (subNode == null) {
    return null;
return getNodeValue(subNode, subNodeName);
StringgetTagName(Node labelNode)
get Tag Name
if (labelNode.getNodeType() == Node.ELEMENT_NODE) {
    return labelNode.getNodeName();
return null;
StringgetTagName(Node node)
get Tag Name
if (node instanceof Element)
    return ((Element) node).getTagName();
else
    return null;