我有一个包含多个父级嵌套子级的 XML 文件,我想添加一个新的“订单”标签来指示他们的订单。
目前我有类似的东西
<root>
<level id='FRUITS'>
<level id='APPLE'>
<heading>APPLE HEADER </heading>
<level id='APPLE_ONE'>
<file fileName='APPLE_ONE_I' />
<heading>This is Apple One I.</heading>
<file fileName='APPLE_ONE_II' />
<heading>This is Apple One II.</heading>
</level>
<level id='APPLE_TWO'>
<file fileName='APPLE_TWO_II' />
<heading>This is Apple One I.</heading>
</level>
</level>
<level id='ORANGE'>
<heading>ORANGE HEADER</heading>
<level id='ORANGE_ONE'>
<file fileName='ORANGE_ONE_I' />
<heading>This is Orange One I.</heading>
</level>
</level>
</level>
</root>
我需要为 ID 的顺序添加一个指示符,而不是文件。所以它看起来像
<root>
<level id='FRUITS' order='1'>
<level id='APPLE' order='1'>
<heading>APPLE HEADER</heading>
<level id='APPLE_ONE' order='1'>
<file fileName='APPLE_ONE_I' />
<heading>This is Apple One I.</heading>
<file fileName='APPLE_ONE_II' />
<heading>This is Apple One II.</heading>
</level>
<level id='APPLE_TWO' order='2'>
<file fileName='APPLE_TWO_II' />
<heading>This is Apple One I.</heading>
</level>
</level>
<level id='ORANGE' order='2'>
<heading>ORANGE HEADER</heading>
<level id='ORANGE_ONE' order='1'>
<file fileName='ORANGE_ONE_I' />
<heading>This is Orange One I.</heading>
</level>
</level>
</level>
</root>