使用xmlstarlet编辑Android清单文件

huangapple go评论45阅读模式
英文:

Edit android manifest file with xmlstarlet

问题

我正在尝试使用xmlstarlet编辑Android清单文件。我想要更改包属性节点。

输入文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.demoapp">
</manifest>

期望的输出:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.prod.demoapp">
</manifest>

我尝试了一些方法,我认为问题出在命名空间上。我无法选择包属性,因为它的值(例如com.test.demoapp)是一个变量。

尝试使用命名空间的命令:

xmlstarlet edit -N N="http://schemas.android.com/apk/res/android" \
--update "//N:manifest[@name='package']/@value" \
--value "com.prod.demoapp" $androidManifestXMLfile

我也尝试了不使用命名空间的命令:

xmlstarlet edit \
--update "//manifest[@name='package']/@value" \
--value "com.prod.demoapp" $androidManifestXMLfile

但在这两种情况下,都没有发生任何更改。输出仍然是xml文件的内容。

英文:

I am trying to edit android manifest file with xmlstarlet. I want to change package attribute node.

Input file:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.test.demoapp&quot;&gt;
 &lt;/manifest&gt;

expected output:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.prod.demoapp&quot;&gt;
 &lt;/manifest&gt;

I tried few things, I think it's a issue with namespace. I am unable to select package attribute since it's value package name(e.g. com.test.demoapp) is a variable.

    xmlstarlet edit -N N=&quot;http://schemas.android.com/apk/res/android&quot; \
    --update &quot;//N:manifest[@name=&#39;package&#39;]/@value&quot; \
    --value &quot;com.prod.demoapp&quot; $androidManifestXMLfile

I also tried without namespace

    xmlstarlet edit \
    --update &quot;//manifest[@name=&#39;package&#39;]/@value&quot; \
    --value &quot;test&quot; $androidManifestXMLfile

But in both cases nothing is changed. Output is content of xml file.

答案1

得分: 1

您选择的具有属性name=&#39;package&#39;manifest标签与任何内容都不匹配。

而是像这样仅选择package属性本身:

xmlstarlet edit \
--update &quot;//manifest/@package&quot; \
--value &quot;com.prod.demoapp&quot; $androidManifestXMLfile
英文:

Your selection of a manifest tag with attribute name=&#39;package&#39; does not match anything.

Instead just select the package attribute itself like this:

xmlstarlet edit \
--update &quot;//manifest/@package&quot; \
--value &quot;com.prod.demoapp&quot; $androidManifestXMLfile

huangapple
  • 本文由 发表于 2023年6月8日 19:50:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431573.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定