0

I have an xml, simplified version is below. I need to sort variable elements by name subelements.

<task>
  <name>tsk name</name>
  <id>123</id>
  <agent />
  <variable>
    <name>var 687</name>
    <value>3</value>
    <chld>hgkj</chld>
  </variable>
  <variable>
    <name>var 246</name>
    <value>2</value>
    <chld>khgkj</chld>
  </variable>
  <variable>
    <name>var 296</name>
    <value>9</value>
    <chld>fjhgf</chld>
  </variable>
</task>

I need to have variable element with name subelement with value 246 first, variable element with name subelement with value 296 second and variable element with name subelement with value 687 last. I know how to sort elements but I do not know how to sort them by certain subelements. I also have no attributes to sort the variable elements by. Would anybody help me?

JanFi86
  • 449
  • 10
  • 29
  • Possible duplicate of [Sorting XML in python etree](https://stackoverflow.com/questions/25338817/sorting-xml-in-python-etree) – René Höhle Jun 13 '19 at 20:39
  • I saw the question and its solution, but I think this is different case. I have no attributes to sort variable elements by. I need to sort them by name subelement. – JanFi86 Jun 13 '19 at 20:44

0 Answers0