输入文件:
<myroot>
<nodeA id="a">
<section id="i">
<item id="0" method="a"> <!-- parent section id="i" , keep this node-->
<somechild>a</somechild>
</item>
<item id="1" method="a">
<otherchild>a</otherchild>
</item>
</section>
<cell id="i">
<part id="1" method="b"> <!-- parent cell id="i", keep this node-->
<attr>u</attr>
</part>
</cell>
<section id="i">
<item id="0" method="a"> <!-- parent section id="i", remove this node-->
<type>blah</type>
</item>
<item id="3" method="a">
<other>xx</other>
</item>
<item id="0" method="b"> <!-- this has same id but different method, so we keep this -->
<otherchild>a</otherchild>
</item>
</section>
<cell id="i">
<part id="1" method="b"> <!-- parent cell id="i", remove this node -->
<attr>y</attr>
</part>
</cell>
</nodeA>
<nodeA id="b">
<section id="i">
<item id="1" method="a">
<otherchild>a</otherchild>
</item>
</section>
<section id="i">
<item id="0" method="a">
<type>blah</type>
</item>
<item id="1" method="a">
<other>xx</other>
</item>
</section>
</nodeA>
<nodeB id="a">
<cell id="i">
<part id="1" method="b">
<attr>u</attr>
</part>
</cell>
<section id="i">
<item id="0" method="a">
<type>blah</type>
</item>
</section>
<cell id="i">
<part id="1" method="b">
<attr>y</attr>
</part>
</cell>
</nodeB>
</myroot>
输出:
<myroot>
<nodeA id="a">
<section id="i">
<item id="0" method="a">
<somechild>a</somechild>
</item>
<item id="1" method="a">
<otherchild>a</otherchild>
</item>
</section>
<cell id="i">
<part id="1" method="b">
<attr>u</attr>
</part>
</cell>
<section id="i">
<item id="3" method="a">
<other>xx</other>
</item>
<item id="0" method="b"> <!-- this has same id but different method, so we keep this -->
<otherchild>a</otherchild>
</item>
</section>
</nodeA>
<nodeA id="b">
<section id="i">
<item id="1" method="a">
<otherchild>a</otherchild>
</item>
</section>
<section id="i">
<item id="0" method="a">
<type>blah</type>
</item>
</section>
</nodeA>
<nodeB id="a">
<cell id="i">
<part id="1" method="b">
<attr>u</attr>
</part>
</cell>
<section id="i">
<item id="0" method="a">
<type>blah</type>
</item>
</section>
</nodeB>
</myroot>
任何人都可以帮助我进行转换,以便如果一个节点出现两次或多次并且具有相同的父 id,我们只保留第一次出现而忽略其他节点。文件中还有另一个元素,<nodeB></nodeB>
即<nodeC></nodeC>
. 等等。非常感谢。约翰