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);
}
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);
}