使用xmllint从XML文件中提取属性
这是我的XML的一部分:使用xmllint从XML文件中提取属性,xml,xpath,xml-parsing,xmllint,Xml,Xpath,Xml Parsing,Xmllint,这是我的XML的一部分: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <nlpcmp> <word string="getuserscount" occurrences="2"> <systems> <system name="mks"> <pos file="IrcChannel.cpp" part="adjective" line="414
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<nlpcmp>
<word string="getuserscount" occurrences="2">
<systems>
<system name="mks">
<pos file="IrcChannel.cpp" part="adjective" line="414" occ="2"/>
</system>
</systems>
</word>
<word string="setuserprivilege" occurrences="2" >
<systems>
<system name="mks">
<pos file="IrcChannel.cpp" part="adjective" line="375" occ="2"/>
</system>
</systems>
</word>
<word string="hasprivilege" occurrences="2" >
<systems>
<system name="mks">
<pos file="IrcChannel.cpp" part="verb" line="360" occ="2"/>
</system>
</systems>
</word>
<word string="partmessage" occurrences="2" >
<systems>
<system name="TEST">
<pos file="IrcChannel.cpp" part="verb" line="308" occ="2"/>
</system>
</systems>
</word>
</nlpcmp>
所以我尝试了这个命令:
xmllint --xpath 'string(//nlpcmp/word/@name)' file.xml
没有输出,然后我尝试:
xmllint --xpath "//*[local-name()='word'][system/@name[mks]" file.xml
上面写着:
XPath错误:无效谓词
XmlXpathVal:评估失败
然后我试着
xmllint --xpath "//*[local-name()='word']" file.xml
它给了我“word”标签的所有内容,我不想要。我只需要绳子。我该怎么做 此xmllint命令
xmllint --xpath "/nlpcmp/word[systems/system/@name = 'mks']/@string" file.xml
将产生这个输出
getuserscount
setuserprivilege
hasprivilege
按要求
getuserscount
setuserprivilege
hasprivilege