xmlstarlet 不适用于字符串锚点 $
xmlstarlet does not work with end of string anchor $
使用 xmlstarlet 显示的 xpath 语句,它不支持字符串锚点的结尾,并选择 'aaa' 和 'bbb'。如何构造 xpath 语句以匹配以 998 结尾的属性?
Xpath 语句:
-v "../Property[contains(@Name, '998$')]
XML数据
<Object>
<Property Name="1230-02324998">
<Value>aaa</Value>
</Property>
<Property Name="3223-99824993">
<Value>bbb</Value>
</Property>
</Object>
contains
函数不支持任何正则表达式。使用 Property[substring(@Name, string-length(@Name) - 2) = '998']
.
Tried this: xmlstarlet sel -B -t -m "//Object" -v "..Property[substring(@Name, string-length(@Name) - 2) = '998']" The answer should be: "aaa", but it didn't work.
在 shell 中输入问题的答案时请小心。 Martin Honnen 没有告诉您表达式以 ..
开头,这使其成为无效表达式。
鉴于您的 XML 输入存储在名为 "object.xml" 的 XML 文档中:
$ xml sel -B -t -m "Object" -v "Property[substring(@Name, string-length(@Name) - 2) = '998']" object.xml
aaa
使用 xmlstarlet 显示的 xpath 语句,它不支持字符串锚点的结尾,并选择 'aaa' 和 'bbb'。如何构造 xpath 语句以匹配以 998 结尾的属性?
Xpath 语句:
-v "../Property[contains(@Name, '998$')]
XML数据
<Object>
<Property Name="1230-02324998">
<Value>aaa</Value>
</Property>
<Property Name="3223-99824993">
<Value>bbb</Value>
</Property>
</Object>
contains
函数不支持任何正则表达式。使用 Property[substring(@Name, string-length(@Name) - 2) = '998']
.
Tried this: xmlstarlet sel -B -t -m "//Object" -v "..Property[substring(@Name, string-length(@Name) - 2) = '998']" The answer should be: "aaa", but it didn't work.
在 shell 中输入问题的答案时请小心。 Martin Honnen 没有告诉您表达式以 ..
开头,这使其成为无效表达式。
鉴于您的 XML 输入存储在名为 "object.xml" 的 XML 文档中:
$ xml sel -B -t -m "Object" -v "Property[substring(@Name, string-length(@Name) - 2) = '998']" object.xml
aaa