在 bash 中使用 xmlns 获取 xmllint 属性
Getting xmllint property with xmlns in bash
有以下 config.xml 文件(该文件来自源存储库,我不能在自动化过程中更改它;我可以更改构建过程,但是关于如何提取两个属性的想法,androidversionCode并且 iosCFBundleVersion 将不胜感激。
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.company.project" version="1.2.8" androidversionCode="209" iosCFBundleVersion="209" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Project name</name>
<description>Project description</description>
</widget>
我的尝试:
$ xmllint --xpath "string(//widget/@id)" config.xml
仅当从文件中删除 xmlns="http://www.w3.org/ns/widgets" 时才有效。如果我设置 xmlns="" 那么它也可以工作,但我发现没有其他情况会返回 id 或任何版本代码。所以,xmlns="something" 使 xpath 失败,对吧?
我怎样才能让它工作并获取那些版本号?
分辨率为:
xmllint --xpath 'string(//*[local-name()="widget"]/@id)' config.xml
有以下 config.xml 文件(该文件来自源存储库,我不能在自动化过程中更改它;我可以更改构建过程,但是关于如何提取两个属性的想法,androidversionCode并且 iosCFBundleVersion 将不胜感激。
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.company.project" version="1.2.8" androidversionCode="209" iosCFBundleVersion="209" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Project name</name>
<description>Project description</description>
</widget>
我的尝试:
$ xmllint --xpath "string(//widget/@id)" config.xml
仅当从文件中删除 xmlns="http://www.w3.org/ns/widgets" 时才有效。如果我设置 xmlns="" 那么它也可以工作,但我发现没有其他情况会返回 id 或任何版本代码。所以,xmlns="something" 使 xpath 失败,对吧?
我怎样才能让它工作并获取那些版本号?
分辨率为:
xmllint --xpath 'string(//*[local-name()="widget"]/@id)' config.xml