Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] How to read attribute value from Nodes class.

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Regier Avery J <RegierAveryJ AT JohnDeere.com>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] How to read attribute value from Nodes class.
  • Date: Thu, 3 May 2012 16:00:23 -0500

I'm going to start with some context to my question.
Here's my test document:

<?xml version="1.0" encoding="UTF-8"?>
<response xmlns="http://some.namespace";>
<body>
<bag id="1" rel="self" uri="/bags/1">
<name>Bag 1</name>
<item id="1" rel="self" uri="/items/1">
<name>Item 1</name>
<code>ABC1</code>
</item>
<item id="2" rel="self" uri="/items/2">
<name>Item 2</name>
<code>ABC2</code>
</item>
</bag>
</body>
</response>

Here's my path:
//a:*[not(self::code)]|//@id

I have bound 'a' to http://some.namespace in the XPathContext.

private Nodes query(Document doc, String xpath, XPathContext
xpathContext)
throws ContextException {
Nodes nodes;
try {
nodes = doc.query(xpath, xpathContext);
} catch(nu.xom.XPathException e) {
// throw a ContextException
}
return nodes;
}

I need to select all elements in the document that aren't 'a:code' and select
all the 'id' attributes but not any of the others. This is just one example.
I am going to limit the response xml to only what the path 'passes'.

As far as I can tell from various books and documentation, //* is not
supposed to select anything on the namespace axis. Nevertheless, it appears
that XOM is doing exactly that, and I get the following error.

Caused by: nu.xom.XPathException: XPath error: No Such Function
{http://axiom.deere.com/Platform/Data/Services}:not
at nu.xom.Node.query(Unknown Source)
at
com.deere.axiom.rest.followpass.domain.XomFollowPass.query(XomFollowPass.java:159)
... 28 more
Caused by: nu.xom.jaxen.UnresolvableException: No Such Function
{http://axiom.deere.com/Platform/Data/Services}:not
at nu.xom.jaxen.SimpleFunctionContext.getFunction(Unknown Source)
at nu.xom.jaxen.ContextSupport.getFunction(Unknown Source)
at nu.xom.jaxen.Context.getFunction(Unknown Source)
at nu.xom.jaxen.expr.DefaultFunctionCallExpr.evaluate(Unknown Source)
at nu.xom.jaxen.expr.DefaultPredicate.evaluate(Unknown Source)
at nu.xom.jaxen.expr.PredicateSet.applyPredicate(Unknown Source)
at nu.xom.jaxen.expr.PredicateSet.evaluatePredicates(Unknown Source)
at nu.xom.jaxen.expr.DefaultNameStep.evaluate(Unknown Source)
at nu.xom.jaxen.expr.DefaultLocationPath.evaluate(Unknown Source)
at nu.xom.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(Unknown
Source)
at nu.xom.jaxen.expr.DefaultUnionExpr.evaluate(Unknown Source)
at nu.xom.jaxen.expr.DefaultXPathExpr.asList(Unknown Source)
at nu.xom.jaxen.BaseXPath.selectNodesForContext(Unknown Source)
at nu.xom.jaxen.BaseXPath.selectNodes(Unknown Source)
at nu.xom.JaxenConnector.selectNodes(Unknown Source)
... 30 more

I've tried everything I can think of to modify the xpath statement to ignore
nodes on the namespace axis for this query to no avail.

Ideas on how to work around this? Is this a bug or actually correct
according to the spec?

Thanks,
Avery J. Regier
RegierAveryJ AT JohnDeere.com




Archive powered by MHonArc 2.6.24.

Top of Page