使用以下file.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
<index type="I8">
<book>2</book>
</index>
</config>我不能用选择书
xmlstarlet sel --template --match /config/index[@type="I8"] -c . file.xml我不能用选择书
xmlstarlet sel --template --match /config/index[@type='I8'] -c . file.xmlI 可以用
xmlstarlet sel --template --match "/config/index[@type='I8']" -c . file.xmlI 可以用
xmlstarlet sel --template --match '/config/index[@type="I8"]' -c . file.xml此外,如果xml中的类型是type="8“,则可以使用选择它:
xmlstarlet sel --template --match /config/index[@type="8"] -c . file.xml为什么?
xmlstarlet 1.6.1
compiled against libxml2 2.9.4, linked with 20904
compiled against libxslt 1.1.29, linked with 10129发布于 2020-04-07 06:21:51
这个程序可以工作(在Windows和Ubuntu上进行测试):
xmlstarlet sel -t -i /config/index/@type=\"I8\" -m //book -c . -b file.xml它与引用有关,在查看下一个语句的输出时,您可以看到为什么:
xmlstarlet sel -C --template --match /config/index[@type="I8"] -c . file.xml它的输出:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="/config/index[@type=I8]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>在I8中缺少引号。
https://stackoverflow.com/questions/60839966
复制相似问题