[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

querying an xml file with namespaces

Wolfgang Hoschek wolfgang.hoschek at mac.com
Wed Jan 11 14:51:29 PST 2006


querying an xml file
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.




PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.