Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xmllint从XML文件中提取属性_Xml_Xpath_Xml Parsing_Xmllint - Fatal编程技术网

使用xmllint从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的一部分:

<?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