0

I have an xml file beginning with

<?xml version='1.0' encoding='utf-8'?>
<widget 
  id="io.ionic.starter" 
  version="0.0.1" 
  xmlns="http://www.w3.org/ns/widgets" 
  xmlns:cdv="http://cordova.apache.org/ns/1.0"
>

I need to add a ios-CFBundleVersion="de.test" attribute so it should look like this:

<?xml version='1.0' encoding='utf-8'?>
<widget 
  id="io.ionic.starter" 
  version="0.0.1" 
  xmlns="http://www.w3.org/ns/widgets" 
  xmlns:cdv="http://cordova.apache.org/ns/1.0"
  ios-CFBundleVersion="de.test"
>

I've tried it with xmlstarlet:

xmlstarlet edit \
  -O \
  --inplace \
  --insert "widget" \
  --type attr \
  -n ios-CFBundleVersion \
  -v de.test \
  config.xml 

but nothing happens in my file config.xml. What would be the correct xmlstarlet command here?

1 Answer 1

3

You forgot that the widget element has a namespace, hence your XPath didn't match. So define one with the -N global option and your command starts to work:

xmlstarlet edit --inplace -O -N x=http://www.w3.org/ns/widgets  \
                --insert "x:widget" --type attr \
                -n "ios-CFBundleVersion" -v "de.test" config.xml
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.