'Sort Any XML Tags using Plain JavaScript or with any Lib

I am looking for a solution to sort any XML tags like: It should Sort child tags under the parent. Here Node* are under root and A,B,C under Node*. So Node* should be sorted and A, B, C under the node should be sorted.

<root>
 <node1>
  <B>text</B>
  <A>another_text</A>
  <C>one_more_text</C>
 </node1>
 <node3>
  <C>one_more_text</C>
  <B>text</B>
  <A>another_text</A>
 </node3>
 <node2>
  <C>one_more_text</C>
  <B>text</B>
  <A>another_text</A>
 </node2>
</root>

To

<root>
 <node1>
  <A>another_text</A>
  <B>text</B>
  <C>one_more_text</C>
 </node1>
 <node2>
  <A>another_text</A>
  <B>text</B>
  <C>one_more_text</C>
 </node2>
 <node3>
  <A>another_text</A>
  <B>text</B>
  <C>one_more_text</C>
 </node3>
</root>

Any JS Libs which support this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source