So, I have the following code, which I pretty much copied from here . But the problem is that my text nodes do not contain any text that has only attributes. Therefore i like
<Random name="Katie" num="5"></Random>
and I use this code to analyze it:
private void listNodes(Node node, String indent)
{
String nodeName = node.getNodeName();
System.out.println(indent + " Node is: " + nodeName);
if(node instanceof Element && node.hasAttributes())
{
System.out.println(indent + "Attributes are: ");
NamedNodeMap attrs = node.getAttributes();
for (int i = 0; i < attrs.getLength(); i++)
{
Attr attribute = (Attr) attrs.item(i);
System.out.println(indent + attribute.getName() + "=" + attribute.getValue());
}
}
NodeList list = node.getChildNodes();
if (list.getLength() > 0)
{
for (int i = 0; i < list.getLength(); i++)
{
listNodes(list.item(i), indent + " ");
}
}
}
For some reason, my empty text nodes say
Node: #text
Does anyone know how to skip empty node text when parsing an XML file?
Thank,
Josh
source
share