2012-03-01 56 views
-2

我已經follwoing XML實例 -XPath表達式爲一個表達式搜索多個標籤

<World> 
    <Continents> 
    <Continent>America</Continent> 
    <Cities> 
      <Country>USA</Country> 
      <City>New York</City> 
    </Cities> 
    <Description>Newyork is a nice city</Description> 
    <Cities> 
      <Country>USA</Country> 
      <City>Philadelphia</City> 
    </Cities> 
    <Description>Philadelphia is a nice city</Description> 
    <Cities> 
      <Country>USA</Country> 
      <City>New Orleans</City> 
    </Cities> 
    <Description>New Orleans is a nice city</Description> 
    </Continents> 
    <Continents> 
    <Continent>Asia</Continent> 
    <Cities> 
      <Country>India</Country> 
      <City>Mumbai</City> 
    </Cities> 
    <Description>Mumbai is a nice city</Description> 
    <Cities> 
      <Country>India</Country> 
      <City>New Delhi</City> 
    </Cities> 
    <Description>New Delhi is a nice city</Description> 
    <Cities> 
      <Country>India</Country> 
      <City>Kolkata</City> 
    </Cities> 
    <Description>Kolkata is a nice city</Description> 
    <Cities> 
      <Country>Japan</Country> 
      <City>Tokyo</City> 
    </Cities> 
    <Description>Tokyo is a nice city</Description> 
    </Continents> 
    </World> 

我想列出以下條件描述 -

Country="India" OR City="New York" 
Continent="Asia" OR Country="Japan" 
+1

請填寫您的問題標題並告訴我們您已經嘗試了什麼。如果你還沒有嘗試過任何東西,請嘗試一下。 – BoltClock 2012-03-01 06:37:12

+0

另請在再次發佈之前閱讀[常見問題]和[問]。 – 2012-03-01 06:39:20

回答

1

嘗試下一個:

//Description[ 
    (preceding-sibling::Cities[1]/Country = "India" or 
    preceding-sibling::Cities[1]/City = "New York" 
) or 
    (preceding-sibling::Continent[1] = "Asia" or 
    preceding-sibling::Cities[1]/Country = "Japan" 
) 
] 

輸出在我的測試中(--NODE--是我的工具添加的文字文本):

<Description>Newyork is a nice city</Description>-- NODE -- 
<Description>Mumbai is a nice city</Description>-- NODE -- 
<Description>New Delhi is a nice city</Description>-- NODE -- 
<Description>Kolkata is a nice city</Description>-- NODE -- 
<Description>Tokyo is a nice city</Description> 
+0

非常感謝.. :) – John 2012-03-02 06:51:09

+0

非常感謝...再次...我對OR和AND用法分別進行了更改。再次感謝:)而且答案值得失去2分。 ;) – John 2012-03-03 13:08:05