If you're using JDOM for parsing XML in Java and you run into the problem that Element#getChild(String) and Element#getChildText(String) just keep returning null, here's a list of reasons why that might be happening:
- The node really doesn't exist!
- The node is in a different namespace and you need to use the version of the method that also accepts the namespace: Element#getChild(String, Namespace) or Element#getChildText(String, Namespace).
- Most importantly, remember that these methods return only immediate descendents of a node! So if you're looking to get a node nested at the nth level, you will need to walk the tree to its parent and only then can you call #getChild() and actually get the child!
1 comment:
That sucks doesn't it? i was hoping jdom would automatically find and return the sub-element
Post a Comment