[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

Michael Kay mhk at mhk.me.uk
Thu Jan 12 08:55:21 PST 2006


declare namespace in xml file
If you want to find elements whose local name is loc and whose namespace uri
is http://ns/uri, write

 declare namespace md="http://ns/uri";
 for $x in //md:loc
 return ...

Note that the prefix you use in the query is unrelated to any prefix used in
the source document, so long as the namespace URIs match.

You don't need the namespace axis to find an element in a particular
namespace. It was provided in XPath 1.0 to allow you to determine all the
namespaces that are in scope for a given element, which is occasionally
useful, for example there are some XML vocabularies where the presence of a
namespace declaration is significant even if no elements or attributes exist
in that namespace. As Wolfgang mentioned, the namespace axis has not been
carried forward from XPath into XQuery, it is replaced by a couple of
function calls to determine the in-scope namespaces for an element: but you
don't need these either.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: http://xquery.com/mailman/listinfo/talk 
> [mailto:http://xquery.com/mailman/listinfo/talk] On Behalf Of Michaël Michaud
> Sent: 11 January 2006 22:18
> To: http://xquery.com/mailman/listinfo/talk
> Subject:  querying an xml file with namespaces
> 
> 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.
> 
> 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"
> 
> Question : what is the simple method to query an xml file using
> namespaces ?
> 
> Thanks a lot.
> 
> Michaël
> _______________________________________________
> http://xquery.com/mailman/listinfo/talk
> http://xquery.com/mailman/listinfo/talk
> 





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.