Hi
I think i found a reasonalbe solution - ill test how it works on huge Documents
here it comes - ill just show the important methods
<pre>
public Main() {
try {
// Build w/ SAX and Xerces, no validation
SAXBuilder b = new SAXBuilder();
// Create the document
doc = b.build(new File(xmlpath));
Element rootElement = doc.getRootElement();
Vector myChilds = getAllElementsWithName(rootElement,"TextElement");
log("Vector myChilds contains " + myChilds.size()+ " elements");
// Output as XML to screen
//XMLOutputter outputter = new XMLOutputter();
//outputter.output(doc, System.out);
} catch (Exception e)
{
log(e.getMessage());
e.printStackTrace();
}
}
//this method returns a Vector of all Elements with the specified name
private Vector getAllElementsWithName(Element elem,String elemName)
throws Exception{
Vector childVector = new Vector(20,1);
findChilds(childVector,elem,elemName);
return childVector;
}
//this method works recursivly through the DOM - putting all Elements in
//the spezicied Vector
private void findChilds(Vector childContainer,Element elem,String elemName)
throws Exception {
List childs = elem.getChildren();
for(int i = 0;i <childs.size();i++) {
Element tmpelem = (Element)childs.get(i);
log("processing node: "+tmpelem.getName());
if(tmpelem.getName().equals(elemName)) {
childContainer.addElement(tmpelem);
log("Element "+elemName+ "found");
}
else {
findChilds(childContainer,tmpelem, elemName);
}
}
}
</pre>
thats it - i like JDOM
[This message has been edited by Holger Prause (edited March 29, 2001).]