[jdom-interest] JDOM Xpath attribute help

john tal avalonmerlinditty at yahoo.com
Tue Mar 2 07:50:18 PST 2004


Any ideas on how to retrieve this value from a
schema-based XML file?  

JDOM tutorials are a little thin on the XPath side of
the house.

Target XML trying to read:

<acknowledgementHeader type="PROCESSED" success="TRUE"
duplicate="FALSE">

This does not work:

			org.jdom.xpath.XPath nodePath =
org.jdom.xpath.XPath.newInstance("/test:envelope/body/response/acknowledge/acknowledgement/acknowledgementHeader");
			Iterator nodeIter =
nodePath.selectNodes(doc).iterator();
			while (nodeIter.hasNext()) 
			{
				org.jdom.Element element =
(org.jdom.Element)nodeIter.next();
				String duplicate =
getString(element,"attr[@name='duplicate']/string");


GetString is defined as:

   protected String getString(org.jdom.Element elem,
String path) throws org.jdom.JDOMException
    {
        org.jdom.xpath.XPath xpath =
org.jdom.xpath.XPath.newInstance(path);
        org.jdom.Element e =
(org.jdom.Element)xpath.selectSingleNode(elem);
        return e!=null ? e.getText() : null;
    }			



__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com



More information about the jdom-interest mailing list