I’ve seen some variations of this quesiton asked here, but I’m not sure how to apply them to my situation, so I’m hoping maybe someone can help me here.
I have a flat XML file in a format similar to this one:
<item id="1"/>
<item id="1.1"/>
<item id="1.1.1"/>
<item id="1.1.2"/>
<item id="1.1.2.1"/>
<item id="1.2"/>
<item id="1.3"/>
I’m looking to set up the tags hierarchically based on the id attribute, like so:
<item id="1">
<item id="1.1">
<item id="1.1.1"/>
<item id="1.1.2">
<item id="1.1.2.1"/>
</item>
</item>
<item id="1.2"/>
<item id="1.3"/>
</item>
Some of the id values have two digit numbers (e.g., “1.2.3.15.1”) which makes comparing them even more challenging.
Help?
Selecting the correct nodes can be tricky but as you have no hierarchy this works for your sample input (if you add a root element to it)