JdeHaan
JdeHaan

Reputation: 392

Adding a new subnode with xmlstarlet almost right

Can not figure out how to get what I want: adding a new subnode with attributes:

cat input.xml | xmlstarlet edit --subnode "//a/b/c" -t elem -n d -v 'e="data3"'

gives me

<a>
  <b>
    <c>
      <d e="data1"/>
      <d e="data2"/>
      <d>e="data3"</d>
    </c>
  </b>
</a>

which is valid xml, as far as I know, but is unacceptable for the app using and defining the file. Is there a way to convince xmlstarlet to produce the output:

<d e="data3"/>

Thanks in advance!

Upvotes: 0

Views: 157

Answers (1)

JdeHaan
JdeHaan

Reputation: 392

The answer, thanks to @zx485:

cat input.xml | xmlstarlet edit --subnode "//a/b/c" -t elem -n 'd e="data3"'

Upvotes: 1

Related Questions