On 10/14/2011 7:00 AM, coffeMan wrote: > I am retrieving XML from a servlet and parsing through it. the xml > code is one large XML file but on through the servlet. I can parse > through it easy and get my results but i am not sure when to stop it. > I keep getting NullPointerException that kicks off when it reaches the > end. I never know when its going to end because every file that i > parse through is different in length. > > I am using the DOM parser. Document messageDom = > XMLParser.parse(srv.getXmlObject()); > > string name = > messageDom.getElementsByTagName("name").item(n).getFirstChild().getNodeValue(); > - n being a variable that is an integer value that increases after > each loop
A couple of questions come to mind: 1) Are you sure the document is valid? Does there exist an XML schema against which you can test this document instance? If not, you might consider creating an XML schema, a sample document, and running the pair through a validating parser such as xmllint. Such validation tests can be a useful part of your overall product verification/validation regime. 2) Have you considered using GQuery to produce nodelists? For complex, valid documents it can be a useful tool. 3) Consider using loops controlled by NodeList.length() instead of using the builder pattern to process the tree. In my experience, using loops instead of the builder pattern yields fewer surprises at runtime. I realize there's a "cool factor" to chaining those method calls, but it usually results in issues such as the one you're now trying to resolve. Bueno Suerte, jec -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.