1

次のサンプルxmlがあります。メーカーIDに基づいて、それに対応するすべての製品名を取得しようとしています。

<root>
  <Component ID="88" BusinessID="ABC">  
    <Product_Name>Apple iPhone 4 16GB Black</Product_Name>  
    <Product_Description>Apple iPhone 4 8GB Black</Product_Description>  
    <Manufacturer ID="1122" xsi:type="MobileHandset_Manufacturer"> 
      <Name>Apple</Name>  
      <Description>Apple</Description> 
    </Manufacturer>       
  </Component>
  <Component ID="98" BusinessID="LMN">  
    <Product_Name>Apple iPhone 4 16GB White</Product_Name>  
    <Product_Description>Apple iPhone 4 8GB White</Product_Description>  
    <Manufacturer ID="1122" xsi:type="MobileHandset_Manufacturer"> 
      <Name>Apple</Name>  
      <Description>Apple</Description> 
    </Manufacturer>       
  </Component>
  <Component ID="77" BusinessID="XYZ">  
    <Product_Name>Samsung Galaxy 16GB Green</Product_Name>  
    <Product_Description>Samsung Galaxy 16GB Green</Product_Description>  
    <Manufacturer ID="1177" xsi:type="MobileHandset_Manufacturer"> 
      <Name>Samsung</Name>  
      <Description>Samsung</Description> 
    </Manufacturer>       
  </Component>
</root>

したがって、ID 1122 を使用して、次の製品名を取得したいと思います: Apple iPhone 4 16GB Black Apple iPhone 4 8GB White

xpath クエリの作成を手伝ってもらえますか?

4

1 に答える 1

0

次のクエリを使用できます。

//Component[Manufacturer[@ID='1122']]/Product_Name/text()

または、結果の処理内容によっては、「/text()」ビットを末尾から離したい場合があります。

一意の値のみを取得する必要があり、XPath 2.0 を使用できる場合は、上記のアドレスを個別値関数でラップできます。

distinct-values(//Component[Manufacturer[@ID='1122']]/Product_Name/text())
于 2013-11-05T18:42:16.237 に答える