Xerces Nodeiterator running out of memory for very small XML

J

Jimmy Zhang

I am trying to use node iterator of Xerces to traverse a DOM tree of a
fairly small XML file.
But I keep getting message saying running out of memory. Can someone take a
look at my code to
see what is wrong?
Thanks,
Jimmy

fi = new FileInputStream(f);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(fi);

DocumentType myDoctype = document.getDoctype();
DocumentImpl myDocImpl = new DocumentImpl(myDoctype);
total = 10000;
Element e = document.getDocumentElement();
TestNodeFilter tnf = new TestNodeFilter();
NodeIterator myIterator = null;
Node nextNode = null;
NamedNodeMap nl = null;
Node temp = null;
for (int i=0;i<total;i++)
{
do{
try{
myIterator = myDocImpl.createNodeIterator( e, 1, null, true);
nextNode = myIterator.nextNode();
//System.out.println("node name is "+nextNode.getNodeName());
if (nextNode!=null){
nl = nextNode.getAttributes();
int z = nl.getLength();
for(int k=0;k<z;k++)
{
temp = nl.item(k);
//System.out.println("attribute name "+temp.getNodeName());
}
}
}catch(DOMException err){
}
}while(nextNode != null);
}
 
E

Enrique

What's with the 10,000? I've taken only a cursory look, but it appears
you are traversing the same information 10,000 times...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top