Can XPath expressions use a default namespace?

Discussion in 'XML' started by Arndt Jonasson, Feb 9, 2007.

  1. 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.)
    Arndt Jonasson, Feb 9, 2007
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Feb 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Èý¹â
    Replies:
    1
    Views:
    558
    William F. Robertson, Jr.
    Jul 29, 2003
  2. Colin Toal
    Replies:
    3
    Views:
    806
    Colin Toal
    Jan 23, 2004
  3. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,611
    Richard Tobin
    Nov 13, 2004
  4. Jason Heyes
    Replies:
    1
    Views:
    442
    Woebegone
    Nov 19, 2004
  5. Max
    Replies:
    2
    Views:
    469
    Joe Kesselman
    Aug 1, 2006
Loading...

Share This Page