Re: [xml] XPath question



On 10.05.2004 18:09, Ed Day wrote:

I am relatively new to XPath, so perhaps there is something I don't
understand here.  I am using the following XPath expression:

/MyElement

to try and match the following simple node:

<MyElement
xmlns="http://test.commerceone.com/global_element/SimpleTypeNested";>true</My
Element>

This is coming back as a non-match. Apparently something in the namespace
declaration is causing this.  If I remove that, or replace it with an
attribute of a different name, the match is done OK.  The question is, if
information on the namespace is required in the expression, what should it
be?  Since it is the default namespace, it does not have a prefix.  So I
don't know how to get this to match.

I am using the latest version of libxml2, but I am not sure this is a
libxml2 problem.  I got the same result when I used a different XPath tool.
I am hoping some XPath guru out there can tell me what I am doing wrong.

Consider this document:

  <doc>
    <a xmlns="some-ns">
      <n/>
    </a>
    <b xmlns="another-ns">
      <n/>
    </b>
  </doc>

Now assume that those 'n' nodes inherit the default namespace from their parents. How would you construct an XPath expression which selects any one of the two 'n' nodes, but not the other?

To skip the boresome details, you cannot do what you are trying to. You must give your namespace a prefix and include that prefix in your XPath expression.

Ciao,
Igor




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]