我下面的输入 xml 在子根标记下有许多 'a' 元素。无论哪个“a”组,有一个keyid,不以“ab”开头,都应该在前面的“a”元素下,它以“ab”(keyid元素)开头。输出将有一个新标签“subdetail”。这是我想要的输出。如果没有子组,则输出中将不存在子细节元素。输入xml
<Root>
<subroot>
<a>
<keyid>ab123456</keyid>
<detail>hi</detail>
</a>
<a>
<keyid>09876</keyid>
<detail>undermain1</detail>
</a>
<a>
<keyid>087564</keyid>
<detail>undermain2</detail>
</a>
<a>
<keyid>ab4567</keyid>
<detail>hi</detail>
</a>
<a>
<keyid>056432</keyid>
<detail>undermain1</detail>
</a>
</subroot>
</Root>
期望的输出
<Root>
<subroot>
<a>
<keyid>ab123456</keyid>
<detail>hi</detail>
<subdetail>
<detail>undermain1</detail>
</subdetail>
<subdetail>
<detail>undermain2</detail>
</subdetail>
</a>
<a>
<keyid>ab4567</keyid>
<detail>hi</detail>
<subdetail>
<detail>undermain1</detail>
</subdetail>
</a>
</subroot>
</Root>