[xquery-talk] querying an xml file with namespaces
Wolfgang Hoschek
wolfgang.hoschek at mac.com
Wed Jan 11 14:51:29 PST 2006
On Jan 11, 2006, at 2:17 PM, Michaël Michaud wrote:
> Hello,
>
> I try to query an xml file with nux XQueryUtil.
> First time, i get messages such as
> "Prefix md has not been declared"
>
> I could get the result by adding something like
> "declare namespace md="http://www.isotc211.org/2005/gmd";"
> in front of my query string.
That's the standard and hence recommended way of doing it.
>
> Now I try to read the namespaces first with another query
> XQueryUtil.xquery(node, "//namespace::*")
> to automatically add the namespaces in front of my main query,
> but I get the message :
> "The namespace axis is not available in XQuery"
This simply won't work. The namespace axis has been deprecated by the
W3C, so Saxon followed suit and disabled it a few releases ago by
toggling an internal flag. Namespaces continue to be available
supported, of course. It's just the namespace axis iteration that's
gone.
>
> Question : what is the simple method to query an xml file using
> namespaces ?
Depends on what you're trying to do.
You could write yourself a Java method or XQuery function that
computes the namespaces in scope for a given element, then precede
the query with the relevant declarations. For example, using standard
XQuery functions such as fn:namespace-uri(Node) or similar.
The best solution might be to argue on the XOM mailing list for a
public method returning the namespace declarations of a XOM
XPathContext, such as nu.xom.XPathContext.toMap(). If this would be
public I'd consider adding a query method that takes an XPathContext
as additional input parameter, similar to the XOM XPath functionality.
Wolfgang.
More information about the talk
mailing list