Declaring The Null Namespace
Added by Anonymous over 16 years ago
Legacy ID: #5036175 Legacy Poster: Andrew Waters (andrew5)
Hi all, Apologies if this has been asked before - I've done a search and have been unable to find the answer.... I want to define the "null namespace" in my xquery as one of my input XML files has no namespace declared. I've tried: declare namespace nx = ""; And this works fine in XMLSpy (I know it's not the best). In Saxon (9.0.0.4) I just get the error: "Prefix nx has not been declared" Any pointers gratefully received. Thanks Andrew.
Replies (2)
RE: Declaring The Null Namespace - Added by Anonymous over 16 years ago
Legacy ID: #5036827 Legacy Poster: Michael Kay (mhkay)
In XQuery, as in XML namespaces 1.1, declare namespace n = ''; does not associate prefix "n" with the null namespace, rather it undeclares the prefix "n" so that it is no longer associated with anything. Which is why any attempt to use "n" therefore gives a message saying the prefix is undeclared. See XQuery 1.0 section 4.12: If the URILiteral part of a namespace declaration is a zero-length string, any existing namespace binding for the given prefix is removed from the statically known namespaces. If you want to refer to names in the "null namespace", the only way to do it is by using an unprefixed name, and by not declaring any default namespace. That can be a bit of a pain if your input is in a namespace and your output isn't, or vice versa, which is why XSLT 2.0 introduced the idea of having different default namespaces for the input and output. Unfortunately XQuery didn't go the same way. Michael Kay
RE: Declaring The Null Namespace - Added by Anonymous over 16 years ago
Legacy ID: #5036829 Legacy Poster: Michael Kay (mhkay)
"And this works fine in XMLSpy" Altova are sometimes known to do what they think the spec ought to have said. It can be tempting, but it's not in the user's best interests in the long term.
Please register to reply