How to swap the positions of two siblings: using xmlstarlet

54 Views Asked by At

How do I swap the positions of two siblings:

From:

<article>
    <name>
     <firstname>John</firstname>
     <surname>Pettterson</surname>
    </name>
</article>

to:

<article>
    <name>
      <surname>Pettterson</surname>
     <firstname>John</firstname>
    </name>
</article>

This is what I did:

xmlstarlet ed  -L   -i "//article/name/givenname" -t elem -n "surname1" -v "$(xmlstarlet sel -t -v  "//article/name/surname" swapelment.xml)" swapelment.xml
xmlstarlet ed -L -d  "//article/name/surname" swapelment.xml
xmlstarlet ed -L --rename "//article/name/surname1" -v "surname" swapelment.xml 

The first command did not work.

Thanks in advance. Ofuuzo

0

There are 0 best solutions below