2

I have config.xml with following line inside.

<widget id="dev.apk" version="2.5-dev" android-versionCode="20500-dev">

I'd like to change value of attributes 'version', 'id', and 'android-versionCode' in my Bash script.

In the script I have access to ID, VERSION an VERSION_CODE variables, like this:

ID ="release.apk"
VERSION="2.5"
VERSION_CODE="20500"

I'd like to use xmlstarlet or sed. What would be the best way?

Update

My .xml file looks like this:

<?xml version="1.0" encoding="utf-8"?> 
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" id="app" version="2.5" android-versionCode="20500"> 
<name>App title</name> 
<description>Dummy dummy text.</description> 
</widget>

2 Answers 2

2

You can do this to edit in-place the xml file :

Example for id attribute :

xmlstarlet edit -L -u "/_:widget/@id" -v "$ID" file.xml

You just have now to adapt this snippet for the other ones.

NOTE

  • The _: in the Xpath expression is for taking care of the XML namespace
Sign up to request clarification or add additional context in comments.

1 Comment

@LadislavMaxa: Please, remove your deprecated comments
0

You could do something like the below in sed.

sed -i "s|dev.apk|$ID|g" test.xml

But if you are already using a build tool you might want to have a look at replacing your values with placeholder and having targeted environment files

I believe that there is some placeholder support in gradle

http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger

1 Comment

But XML file is not for Android, it's for Cordova.

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.