Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中使用xmlns获取xmllint属性_Xml_Bash_Xpath_Xmllint - Fatal编程技术网

在bash中使用xmlns获取xmllint属性

在bash中使用xmlns获取xmllint属性,xml,bash,xpath,xmllint,Xml,Bash,Xpath,Xmllint,下面是config.xml文件(该文件来自一个源存储库,我无法在自动化过程中更改它;我可以更改构建过程,尽管如此,对于如何提取两个属性(androidversionCode和IOSCBundLeverVersion)的想法将不胜感激 <?xml version='1.0' encoding='utf-8'?> <widget id="com.company.project" version="1.2.8" androidversionCode="209" iosCFBundle

下面是config.xml文件(该文件来自一个源存储库,我无法在自动化过程中更改它;我可以更改构建过程,尽管如此,对于如何提取两个属性(androidversionCode和IOSCBundLeverVersion)的想法将不胜感激

<?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>
这仅在xmlns=”时有效http://www.w3.org/ns/widgets“从文件中删除。如果我设置xmlns=”“,那么它也可以工作,但我没有发现它会返回id或任何版本代码。因此,xmlns=“something”会使xpath失败,对吗

我如何才能做到这一点并获取这些版本号?

解决方案是:

xmllint --xpath 'string(//*[local-name()="widget"]/@id)' config.xml
相关的:
xmllint --xpath 'string(//*[local-name()="widget"]/@id)' config.xml