[xquery-talk] querying an xml file with namespaces
mhk at mhk.me.uk
Thu Jan 12 08:55:21 PST 2006
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
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.
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Michaël Michaud
> Sent: 11 January 2006 22:18
> To: talk at xquery.com
> Subject: [xquery-talk] querying an xml file with namespaces
> 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.
> talk at xquery.com
More information about the talk