Hi James,

[EMAIL PROTECTED] wrote on 27/11/2006 11:27:20 AM:
> I have been using java for quite a while, but this is my first 
> experience with the DOM parser and Xerces.  My issue is that I can't
> seem to get the parser to parse a very simple XML file.

I tried out the code sample you provided (with the exception that I hard 
coded the String variable instead of using a WebResponse object) and it 
worked fine for me, using Xerces 2.9.0.  I assume you've verified that the 
"text" variable contains the XML that you expect it to contain?  Have you 
tried executing the piece of code that you sent as a standalone 
application to verify that it's really that section that's causing the 
problem?

> The NodeList nl, is empty (verified by eclipse debugger).  This I 
> just do not uderstand, the XML is well-formed and very simple and I 
> should be able to get something by tag name even without a DTD.

One caveat is that the NodeList object will look like it is empty in a 
debugger when you first get it.  For performance reasons, Xerces defers 
filling the NodeList until you actually ask for nodes from the list.  If 
you call getLength() on the NodeList, it will walk the entire DOM tree and 
fully populate the list.  If you call item(N) without calling getLength(), 
Xerces will find only the first N items without parsing the entire XML 
tree.  This is useful in cases where you're processing a large DOM tree 
but only want the first occurrence of a particular tag.

Cheers,
-- 
Peter McCracken
XML Parser Development
IBM Toronto Lab
Email: [EMAIL PROTECTED]

Reply via email to