开发者

How can I return a specific node when there are different selection criteria/depths with xpath?

开发者 https://www.devze.com 2022-12-19 14:36 出处:网络
Given the following XML, <root> <property> <programs> <program>1</program> <program>5</program>

Given the following XML,

<root>
    <property>
        <programs>
            <program>1</program>
            <program>5</program>
        </programs>
        <tool>
        </tool>
    </property>
    <property>
        <tool>
            <progra开发者_开发技巧ms>
                <program>1</program>
                <program>2</program>
            </programs>
        </tool>
    </property>
</root>

how would I write an XPath expression to return a collection containing the "property" nodes when program=1? I think I want to write something like "give me all the property nodes when self or a descendant contains programs[program=1]", but can't get it to just give me the "property" nodes...


property[.//programs/program=1]

Selects the property elements that contain descendant programs elements that contain a child program element who's value is 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消