[ajug-members] To JDOM or to not JDOM...that is the question..
David Chandler
david.chandler at learnjsf.com
Fri Nov 14 14:57:05 EST 2008
This is straightforward with XPath. The xpath query below returns all
elements at any level matching your_child_element_name. More advanced
expressions can be used to specify multiple element names, or you can
use //* and simply find matching names in the node loop using
node.getNodeName().
imports are from org.w3c and javax.xml.xpath
...
Element root = (Element) document.getDocumentElement();
nodeList = (NodeList) xpath.evaluate("//your_child_element_name",
root, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++)
{
Node node = nodeList.item(i);
// Call methods on node to get name, value, cast as Element or
Attribute, etc.
}
/dmc
2008/11/14 Gary Marshall <gwjm56 at gmail.com>:
> All
> I have what I think is a typical data extraction task. Given an input XML
> file, build another XML file containing smaller, more meaningful data
> elements. I was told to use JDOM to complete this task and so far in my
> research I cannot find a way to do this using JDOM. However, heres a
> disclaimer: I'm a newbie at JDOM.
> So I have this very, very large XML file that contains lots and lots of what
> I'll call "parent" elements. Each parent element has lots of child
> elements. I need to capture the parent element and certain child elements
> (not all of the child elements) and build the output XML file. Simple,
> right? I need to navigate the entire XML file and for each parent element
> get certain child elements that belong to that parent.
> To JDOM or not to JDOM? Can anybody point me in the direction where I can
> get an idea as to how to accomplish this task?
> Thanks much for your time.
> Gary
>
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
>
>
More information about the ajug-members
mailing list