使用xmllint从XML文件中提取属性



这是我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" 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

称为mks的系统的字符串列表

输出应该是:

getuserscount
setuserprivilege
hasprivilege

所以我尝试了这个命令:

xmllint --xpath 'string(//nlpcmp/word/@name)' file.xml

没有输出,然后我尝试:

xmllint --xpath "//*[local-name()='word'][system/@name[mks]" file.xml

上面写着:XPath错误:无效谓词xmlXPathEval:求值失败

Then I try

xmllint --xpath "//*[local-name()='word']" file.xml

,它给了我"word"标签的所有内容,这是我不想要的。我只需要琴弦。我该怎么做呢?

这个xmllint命令

xmllint --xpath "/nlpcmp/word[systems/system/@name = 'mks']/@string" file.xml

将产生以下输出

getuserscount
setuserprivilege
hasprivilege
要求

最新更新