'How to change the value of attribute in xmlstarlet

I want to setup a script to change values and keys on android manifest during production build. This is the manifest (removed unnecessary code for simplicity)

    <?xml version="1.0"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sample">
      <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
        <uses-permission android:name="android.permission.INTERNET"/>
        <!-- Branch keys -->
        <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_test_ad82b98f289hfhfoBxfzSNXq"/>
      </application>
    </manifest>

I simply want to change the Branch key with the production one, eg: key_live_0932nfe9hfbf I have tried this

xmlstarlet edit --inplace --update "/manifest/application/meta-data[@android:name='io.branch.sdk.BranchKey']/@android:value" --value "test" $thisDirectory/../android/app/src/main/res/values/strings.xml

and get this output

Undefined namespace prefix: /manifest/application/meta-data[@android:name='io.branch.sdk.BranchKey']/@android:value
Invalid expression: /manifest/application/meta-data[@android:name='io.branch.sdk.BranchKey']/@android:value

when I remove the latest part of xPath @android:value it works but nothing is changed (of course).

What I'm doing wrong? Thanks



Solution 1:[1]

I can't replicate your problem, for some reason, but this seems to be a namespace problem. Try changing your --update parameter to

-update "/manifest/application/meta-data[@android:name='io.branch.sdk.BranchKey']/@*[local-name()='value']"

and see if it works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jack Fleeting