I'm looking for a DOM-style XML parser that doesn't load the entire document. Rather, it would let you get an element, then iterate over the element's children, presenting each child as a DOM node but only loading one child at a time (to conserve memory when there's a large number of children. Where I can get such a parser?
Chandra Patni You can use JDOM API (See also JSR0102) to achieve this effect. The following snippet of code shows how JDOM can be used to get the
java.util.Listof child(ren) of a node. In JDOM, a node is said to be
org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(); org.jdom.Element root = builder.build(new java.io.File("file.xml")).getRootElement(); java.util.List children = root.getChildren(); //...An
org.jdom.Elementcan be convert to
org.jdom.output.DOMOutputterclass. Moreover, JDOM lets you change the modify the document without having to worry about underlying parser. See also: Parsing a very large XML file FAQ.