DocumentBuilderFactory instance is default to namespace un-aware. In the case other than namespace aware, the local name of a node is not populated, and hence, null.
If for some reason you need to use getLocalName() to return a non-null result, you should add that setting explicitly immediately after the set up of DocumentBuilderFactory instance, otherwise, you can use getNodeName() for it or, in case the node is an element, cast it to its subclass Element and use getTagName() for it.
Hi again, I have change somethings. This is my XML:
<!-- This field could be set dinamically and then from a JSP decide which company and which dates are needed-->
I want access to my data in the XML, and this is my javaCode:
Hi, using the code which I have posted before when I ask fo dimension length I got 23 but is not 23 childs
Any idea, please?
I prefer to focus on the impossible, because about the possible we already know too much.
Code without tests simply doesn’t exist!
Code is how we tell our colleagues how we feel about them.
posted 6 years ago
I suggest you use all along getElementsByTagName() if that method you understand better. It also flattens the hierarchical structure so that you can use for instance ecompanyData to get to "visitor" or other more obvious simple Elements directly. That simplifies the algorithm. Then you can use getTextContent() to get the text data you need.
The problem also is that getChildNodes() get literally Element as well as Text nodes. That is why you have to code further conditional to verify a node's type is ELEMENT_NODE before going to lower levels...
Read serious tutorials and practice their examples are more efficient in learning and you form less wrong concepts/impressions by pure imagination during trial and error.