简体   繁体   中英

how to get node and its childs using node's name and a specific attribute value?

note : i am dealing with xml files that i don't know their structure in advance so i can't use XPath
here is an example of my xml files :

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
<HWData>
    <Header time="2013-05-29T13:39:34" uploaded="true" version="1.0" />
    <NE vendorName="Nokia Siemens Networks" NEId="WBTS-431">
        <EQHO vendorName="Nokia Siemens Networks" equipmentHolderId="173" >
            <UNIT vendorName="N" unitId="16" />
            <UNIT vendorName="NOKIA SIEMENS NETWORKS" unitId="225" />
        </EQHO>
        <EQHO vendorName="NSN" equipmentHolderId="40192" >
            <UNIT vendorName="AR" unitId="40267" />
        </EQHO>
    </NE>
    <NE vendorName="Nokia Siemens Networks" NEId="WBTS-261">
        <EQHO vendorName="Nokia Siemens Networks" equipmentHolderId="132" >
          <EQHO vendorName="Nokia Siemens Networks" equipmentHolderId="132-1">
            <UNIT vendorName="NN" unitId="1621" />
          </EQHO>
        </EQHO>
    </NE>
</HWData>

i want to know if i can use for example node name "NE" and attribute value NEID="WBTS-261" to have the hole as result!

result expected :

    <NE vendorName="Nokia Siemens Networks" NEId="WBTS-261">
        <EQHO vendorName="Nokia Siemens Networks" equipmentHolderId="132" >
          <EQHO vendorName="Nokia Siemens Networks" equipmentHolderId="132-1">
            <UNIT vendorName="NN" unitId="1621" />
          </EQHO>
        </EQHO>
    </NE>

can someone put me on the right way to do that any example,idea or suggestion will be appreciated.. thank you

Use XPath. It has a special search language for searching elements in xml. See this page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM