[xml] XPath Node Selection Using ...[@attr="value"]

Date view Thread view Subject view Author view

From: Tim Ruddick (truddick@eng.us.uu.net)
Date: Tue Apr 25 2000 - 16:08:33 EDT


I have an XML document containing text similar to the following snippet:

  <config>
      <tables>
          <table>
              <page-size>8192</page-size>
          </table>
          <index num="1">
              <page-size>512</page-size>
          </index>
          <index num="2">
              <page-size>1024</page-size>
          </index>
      </tables>
  </config>

I'm using libxml v2.0 and I'd like to be able to select one or the other
of those "index" nodes using an XPath expression like

  /config/tables/index[@num="1"]

or

  /config/tables/index[@num="2"]

Unfortunately, when I try this, I get the following message on stderr when
I call xmlXPathEval:

  xmlXPathEval: 2 object left on the stack

Running textXPath, I get the following

  % testXPath -i dano-config.xml '/config/tables/index[@num="1"]'
  xmlXPathEval: 2 object left on the stack
  Object is a Node Set :
  Set contains 1 nodes:
  1 ATTRIBUTE num
        TEXT
        content=1

Doing the same for the "table" node, I get something closer to what I
expect, namely:

  % testXPath -i dano-config.xml '/config/tables/table'
  Object is a Node Set :
  Set contains 1 nodes:
  1 ELEMENT table

I notice that there is a message regarding a problem similar to this on
February 3 ("[xml] XPath Questions"). I'm curious to know whether this is
still a recognized problem, or if I'm doing something wrong.

Thanks!
Tim.

----
Message from the list xml@xmlsoft.org
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@xmlsoft.org


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 02 2000 - 12:30:11 EDT