A
Arndt Jonasson
The definition of XPath 1.0 says
"A QName in the node test is expanded into an expanded-name using the
namespace declarations from the expression context. This is the same
way expansion is done for element type names in start and end-tags
except that the default namespace declared with xmlns is not used: if
the QName does not have a prefix, then the namespace URI is null (this
is the same way attribute names are expanded). It is an error if the
QName has a prefix for which there is no namespace declaration in the
expression context."
As implementor of a program which uses XPath expressions to refer to
XML elements (the XPath expressions being sometimes embedded within
XML instance documents, sometimes supplied by other means), it seems
useful to me to let the program supply a default namespace (if
relevant) to the XPath expressions (*) and for XPath to be able to use
it for unprefixed names.
(*) or even let a larger environment than the XML instance document
determine what an unprefixed element means. For example if two
documents are visible, each wholly within its own namespace, with
top elements respectively "top1" and "top2", the expression
"/top1" would be unique without mentioning the namespace.
But the quoted text above seems to perhaps disallow this, forcing the
interpretation of an unprefixed name to imply the null namespace
instead of a defaulted one. Is that really the case?
(XSLT does enforce this, as does the program 'xmlstarlet', but this
of course does not prove anything one way or the other.)
"A QName in the node test is expanded into an expanded-name using the
namespace declarations from the expression context. This is the same
way expansion is done for element type names in start and end-tags
except that the default namespace declared with xmlns is not used: if
the QName does not have a prefix, then the namespace URI is null (this
is the same way attribute names are expanded). It is an error if the
QName has a prefix for which there is no namespace declaration in the
expression context."
As implementor of a program which uses XPath expressions to refer to
XML elements (the XPath expressions being sometimes embedded within
XML instance documents, sometimes supplied by other means), it seems
useful to me to let the program supply a default namespace (if
relevant) to the XPath expressions (*) and for XPath to be able to use
it for unprefixed names.
(*) or even let a larger environment than the XML instance document
determine what an unprefixed element means. For example if two
documents are visible, each wholly within its own namespace, with
top elements respectively "top1" and "top2", the expression
"/top1" would be unique without mentioning the namespace.
But the quoted text above seems to perhaps disallow this, forcing the
interpretation of an unprefixed name to imply the null namespace
instead of a defaulted one. Is that really the case?
(XSLT does enforce this, as does the program 'xmlstarlet', but this
of course does not prove anything one way or the other.)