1

I just faced a problem with gwt xml parser

the thing is ...

I have xml like

<?xml version="1.0" ?>
<A>
<B>
<C>C1</C>
<C>C2</C>
<C>C3</C>
</B>
<B></B>
</A>
<A>
</A>

and gwt code...

Document document = XMLParser.parse(xml);
NodeList nl= document.getElementsByTagName("A");
Window.alert("threads length = "+nl.getLength());

for some reason nl.getLength() returns 0 that means there is no A tag :( Why that may happen and how to get xml structure correctly?

Any useful comment is appreciated

3
  • 1
    Strictly speaking, an XML document can only contain one top-level (or "root") element node. That has two. This is not an answer, however, because I am ensure how XMLParser will treat somewhat-invalid markup :) Commented Oct 30, 2011 at 5:44
  • +1 @pst ... Oh :) Thank you. That was the problem I guess. I removed additional tag pair and all worked :) Commented Oct 30, 2011 at 5:51
  • 1
    Apart from noting that the input isn't well-formed XML, the other relevant factor is that (I believe) GWT's XMLParser is actually a wrapper around the XML parser provided by the browser's Javascript XML parser implementation. So it might be relevant to know which browser you were using. Commented Oct 30, 2011 at 20:47

1 Answer 1

1

So to close this question...

Strictly speaking, an XML document can only contain one top-level (or "root") element node. That has two.

XMLParser will apparently "not work correctly" for this malformed XML input <-- please feel free to add details here or in a comment :)

Happy coding.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.