views:

86

answers:

2
<?xml version="1.0" encoding="UTF-8"?>
<Country>
  <States>
    <County>
      <popularity>39</popularity>
      <name>Orange</name>
      <id>13811</id>
      <url>http://www.url.gov&lt;/url&gt;
      <overview>Orange County Overview</overview>
      <Cities>
        <City name="City #1" size="big" population="33333"/>
        <City name="City #2" size="medium" population="2222"/>
        <City name="City #3" size="Small" population="111"/>
      </Cities>
    </County>
  </States>
</Country>

What is the equivalent XPath expression of "select [cities] where [name]='Orange'" for the XML above?

Edit 07/27/09 00:29 AM PST:

I got it! Thank you all for the advices, you are are great teachers. I was able to select all attributes from all"City" with

/Country/States/County[name='Orange']/Cities/City

A: 

//*[name="Orange"]/Cities/*

sanxiyn
+1  A: 

//Cities[../name="Orange"]/*

The predicate in brackets [../name="Orange"] is roughly equivalent to a where clause.

vog
/Country/States/County/Cities[../name='Orange'] would be better. Double slashes are terribly inefficient. With the sample document, not a big deal, but for large documents it helps to eliminate full tree scans.
Mads Hansen
"Double slashes are terribly inefficient"?! To my experience, the dependants() operator is quite efficient compared to checking the names of a whole path of XML elements. However, it depends on the index the XPath implementation uses.
vog