Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert an element directly after another element with XMLStarlet?

Tags:

xmlstarlet

With this example XML:

<rootnode>
  <element-a />
  <element-b />
  <element-d />
  <element-e />
</rootnode>

How do I insert element <element-c/> directly after the element <element-b/> using XMLStarlet?

like image 830
Todd Avatar asked Sep 19 '11 15:09

Todd


1 Answers

xml ed -i (or --insert) will put the it before the node, xml ed -a (or --append) will put it after, so you can use either one of:

xml ed -i /rootnode/element-d -t elem -n element-c -v "" file.xml
xml ed -a /rootnode/element-b -t elem -n element-c -v "" file.xml
like image 180
npostavs Avatar answered Oct 28 '22 21:10

npostavs