XML XPATH:如何在XPATH中获取节点及其所有子节点的属性值

时间:2016-09-19 14:10:43

标签: java xml xpath

<Roottag>
<ParentTag isAP="false">
        <Name>Safari Packages</Name>
        <Description>parent tag desc</Description>
        <Number>abc 1234567</Number>
        <Price>78</Price>
        <OfferVal code="XYZ">
            <Value>false</Value>
        </OfferVal>
<ChildTag isCA="false"  id="ABCD">
<Name>Safari Package</Name>
            <Description>Safari Package Summar 2018</Description>
            <Number/>
            <Animal ishealthy="true" id="Tiger123">
                <Name>My Tiger</Name>
                <Description>Bengal Tiger</Description>
                <weight>150.0</weight>
                <DisplayVal avaliable="EC">
                <Value>false</Value>
                </DisplayVal>
                <DisplayVal avaliable="BD">
                <Value>true</Value>
                </DisplayVal>
            </Animal>
            <Animal ishealthy="true" id="Lion456">
                <Name>My Lion</Name>
                <Description>African Lion</Description>
                <weight>195.0</weight>
                <DisplayVal avaliable="EC">
                <Value>true</Value>
                </DisplayVal>
                <DisplayVal avaliable="BD">
                <Value>false</Value>
                </DisplayVal>
            </Animal>
</ChildTag>
<ChildTag isCA="false"  id="ABCD">
<Name>Back Door Feeding Package</Name>
            <Description>Safari Package Summar 2018</Description>
            <Number/>
            <Animal ishealthy="true" id="Tiger123">
                <Name>My Tiger</Name>
                <Description>Bengal Tiger</Description>
                <weight>150.0</weight>
                <DisplayVal avaliable="EC">
                <Value>false</Value>
                </DisplayVal>
                <DisplayVal avaliable="BD">
                <Value>true</Value>
                </DisplayVal>
            </Animal>
            <Animal ishealthy="true" id="Lion456">
                <Name>My Lion</Name>
                <Description>African Lion</Description>
                <weight>195.0</weight>
                <DisplayVal avaliable="EC">
                <Value>true</Value>
                </DisplayVal>
                <DisplayVal avaliable="BD">
                <Value>false</Value>
                </DisplayVal>
            </Animal>
</ChildTag>
</ParentTag>
<Roottag>

此处,我需要<ChildTag><Name>Safari Package</Name>以及<Animal>的{​​{1}} 为真的任何<Displayval>条件传递我需要<value>的所有子节点及其动物id的属性 我在XPATH下面尝试过,我在匹配<Animal>下得到所有子节点。在这种情况下狮子。但是我没有获得<Animal> id ishealthy 属性。

XPATH我在java中试过..

<Animal>

我做错了什么?

0 个答案:

没有答案