I have the following xml:
<root>
<Element1>
<Hierarchy attr="value"/>
<Hierarchy attr="value"/>
<Hierarchy attr="value"/>
<Hierarchy attr="value"/>
</Element1>
<AnotherElement>
<YetAnotherElement>
<Hierarchy attr="value"/>
<Hierarchy attr="value"/>
<Hierarchy attr="value"/>
<Hierarchy attr="value"/>
</YetAnotherElement>
</AnotherElement>
</root>
How to convert 'Hierarchy' messages into tree? i.e.
<root>
<Element1>
<Hierarchy attr="value">
<Hierarchy attr="value">
<Hierarchy attr="value">
<Hierarchy attr="value"/>
</Hierarchy>
</Hierarchy>
</Hierarchy>
</Element1>
<AnotherElement>
<YetAnotherElement>
<Hierarchy attr="value">
<Hierarchy attr="value">
<Hierarchy attr="value">
<Hierarchy attr="value"/>
</Hierarchy>
</Hierarchy>
</Hierarchy>
</YetAnotherElement>
</AnotherElement>
</root>