Marina, the problem is that the XML parser parses whitespace into #text nodes, which causes the NodeList to be of length 7. You can fix this by either removing all whitespace from the XML document (everything on a single line) or by adding the necessary logic into your tree-traversing Java code for ignoring all whitespace nodes.