我需要转换这个 XML 输入:
<root>
<node id="a">
<section id="a_1" method="run">
<item id="0" method="a">
<attribute>
<color>Red</color>
<status>1</status>
<condition>good</condition>
</attribute>
</item>
<item id="0" method="a">
<attribute>
<color>Red</color>
<status>1</status>
<condition>good</condition>
</attribute>
</item>
</section>
<section id="a_2" method="run">
<item id="0" method="a">
<attribute>
<color>Red</color>
<status>1</status>
<condition>good</condition>
</attribute>
</item>
</section>
</node>
<node id="b">
<section id="b_1" method="create">
<user id="b_1a" method="x">
<attribute>
<origin>us</origin>
</attribute>
</user>
<user id="b_1a" method="x">
<attribute>
<origin>us</origin>
</attribute>
</user>
<user id="b_1b">
<attribute>a</attribute>
</user>
</section>
<section id="b_2">
<user id="b_1a" method="x">
<attribute>
<name>John</name>
<origin>us</origin>
</attribute>
</user>
</section>
</node>
</root>
这是预期的输出:
<root>
<node id="a">
<section id="a_1" method="run">
<item id="0" method="a">
<attribute>
<color>Red</color>
<status>1</status>
<condition>good</condition>
</attribute>
</item>
</section>
<section id="a_2" method="run">
<item id="0" method="a">
<attribute>
<color>Red</color>
<status>1</status>
<condition>good</condition>
</attribute>
</item>
</section>
</node>
<node id="b">
<section id="b_1" method="create">
<user id="b_1a" method="x">
<attribute>
<origin>us</origin>
</attribute>
</user>
<user id="b_1b">
<attribute>a</attribute>
</user>
</section>
<section id="b_2">
<user id="b_1a" method="x">
<attribute>
<name>John</name>
<origin>us</origin>
</attribute>
</user>
</section>
</node>
</root>
注意:重复意味着所有子/子都具有相同的值,节点可以有 1 个或多个子,只要它是相同的父(id 和方法相同),我们可以假设它总是在相同的部分(id和方法相同)。
这有可能吗?请赐教
非常感谢。
干杯,约翰