Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Can XPath expressions use a default namespace?

Reply
Thread Tools

Can XPath expressions use a default namespace?

 
 
Arndt Jonasson
Guest
Posts: n/a
 
      02-09-2007

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.)

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-09-2007
Arndt Jonasson wrote:

> 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?


Yes, with XPath 1.0 a name without a prefix selects an element or
attribute in no namespace.

With XPath 2.0 which is now a W3C recommendation things are different,
it introduces a default element/type namespace
<http://www.w3.org/TR/xpath20/#dt-def-elemtype-ns>
and that way a name without a prefix can select an element in that
default element namespace:
<http://www.w3.org/TR/xpath20/#node-tests>



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to dynamic XPath expressions in databinding to XmlDataSource? Thor W Hammer ASP .Net 0 03-14-2006 09:08 AM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Use Parameter value in match or select - 'Parameterized XPath expressions ?' Colin Toal XML 3 01-23-2004 12:39 AM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments