1

私のxml構造は次のようなものです

<items>
<item>
    <brand>
        <id> 3 </id>
     </brand>
    <product>
        <productType>Type 1</productType>
    </product>
</item>
<item>
    <brand>
        <id> 4 </id>
     </brand>
    <product>
        <productType>Type 2</productType>
    </product>
</item>
</items>

ユーザーがブランド ID を提供した場合、製品タイプの値を取得する必要があります。たとえば、ユーザーがブランド ID 3 を入力した場合、製品タイプタイプ 1を返す必要があります。

Xpath式でやってみた

 /items/item/brand[id = 3]/product/productType

しかし、うまくいきません。正しい xpath 式は何でしょう。

4

1 に答える 1

3

XPathクエリが意味するような祖先ではなく、brand兄弟であるため、単純なネストの問題があります。product

単純に次のように変更します。

/items/item[brand/id = 3]/product/productType

結果:

Element='<productType>Type 1</productType>'

http://www.freeformatter.com/xpath-tester.htmlで試してみてください。

于 2013-07-18T10:08:55.720 に答える