使用带命名空间的 xmlstarlet 查询 xml 文件的值

Querying value of xml file using xmlstarlet with namspace

使用这个 xml:

<application xmlns="http://ns.adobe.com/air/application/14.0">
    <id>5555</id>
    <filename>product2</filename>
    <name>prodigy</name>
    <versionNumber>6.5.511</versionNumber>
    <versionLabel>6.5.5110</versionLabel>
</application>

这个命令不起作用,returns 没有:

xml sel -t -c "/application/versionLabel" application.xml

但是,从应用程序中删除 xmlns 属性确实有效。为什么?

试试这个:

 xmlstarlet sel -N x="http://ns.adobe.com/air/application/14.0" -t -m "/x:application/x:versionLabel" -c . -n file

或(使用默认命名空间):

xmlstarlet sel -t -v "/_:application/_:versionLabel" file

输出:

<versionLabel xmlns="http://ns.adobe.com/air/application/14.0">6.5.5110</versionLabel>