Java Utililty Methods XML Node Type

List of utility methods to do XML Node Type

Description

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

Method

Node[]getSubnodesOfType(Node in, int type)
get Subnodes Of Type
NodeList subnodes = in.getChildNodes();
if (subnodes == null)
    return (new Node[0]);
int count = subnodes.getLength();
List holder = new ArrayList();
for (int i = 0; i < count; i++) {
    Node test = subnodes.item(i);
    if (test.getNodeType() == type)
...
StringgetTypeAsString(Node node, boolean cftype)
returns the Node Type As String
String suffix = cftype ? "" : "_NODE";
switch (node.getNodeType()) {
case Node.ATTRIBUTE_NODE:
    return "ATTRIBUTE" + suffix;
case Node.CDATA_SECTION_NODE:
    return "CDATA_SECTION" + suffix;
case Node.COMMENT_NODE:
    return "COMMENT" + suffix;
...
StringgetTypeName(Node nameNode)
get Type Name
Node firstChild = nameNode.getFirstChild();
if (firstChild == null) {
    return null;
String nodeValue = firstChild.getNodeValue();
String nameType = "";
if (nodeValue != null && !nodeValue.trim().isEmpty()) {
    nameType = nodeValue + ".";
...
StringgetTypeName(short nodeType)
Returns the node type name from the node type code
switch (nodeType) {
case Node.ELEMENT_NODE:
    return "element";
case Node.DOCUMENT_NODE:
    return "document";
case Node.TEXT_NODE:
    return "text";
case Node.ATTRIBUTE_NODE:
...
booleanhasParentNodeType(Node n, String tagToMatch)
has Parent Node Type
Node parent = n.getParentNode();
while (parent != null) {
    if (parent.getNodeType() == Node.ELEMENT_NODE) {
        Element element = ((Element) parent);
        String tag = element.getTagName();
        if (tagToMatch.equals(tag)) {
            return true;
    parent = parent.getParentNode();
return false;
StringmapNodeType(short nodeType)
Maps a node type, as returned by to a name.
assert nodeType < nodeTypeMap.length;
String val = nodeTypeMap[nodeType];
if (val == null)
    val = "UNKNOWN!!!";
assert val instanceof String;
return (String) val;