输入文件:
<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>
。 等等。非常感谢。 约翰