How to insert elements with attributes to an XML file using XmlStarlet?
Answers
/xml/block/el[not(@name)]
- As stated in an other answer:
You can't insert an element with an attribute directly but since every edit operation is performed in sequence, you can insert an element and then add an attribute.
The command
xmlstarlet ed -a '/xml/block/el[@name="b"]' \ -t 'elem' -n 'el' -v 0 \ -i '/xml/block/el[not(@name)]' \ -t 'attr' -n 'name' -v 'c'