Inserting both values and child element into a parent element using xmlstarlet

27 Views Asked by At

I want to create a new xml file using xmstarlet to look like this:

  <permissions>
      <license-p> 
           This is an Open Access article distributed under the terms of the Creative Commons Attribution License 
           <ext-link ext-link-type="uri" xlink:href="http://creativecommons.org/licenses/by/4.0/"> http://creativecommons.org/licenses/by/4.0  </ext-link>
          , which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.-……
      </license-p>
    </permissions>

I have managed to get “This is an…" and "ext-link” done, but not the last statement, “,which permits …”

This is what I did:

xmlstarlet ed -L -s "//permissions" -t elem -n "license-p"  -v "This is an Open Access article distributed under the terms of the Creative Commons Attribution License" license.xml

xmlstarlet ed  -L -s "//permissions/license-p" -t elem -n "ext-link" -v "http://creativecommons.org/licenses/by/4.0/" \
 --insert "//permissions/license-p/ext-link"  --type 'attr' -n 'ext-link-type' -v  'uri' \
 --insert "//permissions/license-p/ext-link"  --type 'attr' -n 'xlink:href' -v  'http://creativecommons.org/licenses/by/4.0/' \
 license.xml

I need help on how it can be done in xmlstarlet.

-Ofuuzo

0

There are 0 best solutions below