【问题标题】:xpath conditionals not working with xmllintxpath 条件不适用于 xmllint
【发布时间】:2021-01-16 06:03:30
【问题描述】:

我正在尝试使用条件来使用 xpath 过滤以下 XML 的某些节点。

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE html>
<html>
<body>
<div class="video_wrapper">
  <div class="stretchy-wrapper">
    <video width="1280px" height="720px">
      <source src="video-480p.mp4" type="video/mp4" label="480P" res="480"/>
      <source src="video-720p.mp4" type="video/mp4" label="720P" res="720"/>
      <source src="video.mp4" type="video/mp4" label="1080P" res="1080"/> 
    </video>
  </div>
</div>
</body>
</html>

此 XPath 有效:

xmllint --xpath "//source" ./scratch.xml
<source src="video-480p.mp4" type="video/mp4" label="480P" res="480"/>
<source src="video-720p.mp4" type="video/mp4" label="720P" res="720"/>
<source src="video.mp4" type="video/mp4" label="1080P" res="1080"/>

但事实并非如此:

xmllint --xpath "//source[@res='1000']" ./scratch.xml
XPath set is empty

我的语法有什么错误吗?

附:我系统上的libxml版本是20904

【问题讨论】:

    标签: xml xpath xmllint


    【解决方案1】:

    //source[@res='1000'] 没有选择任何内容,因为您的文档没有这样的 source 元素。

    也许你的意思

    //source[@res='1080']
                     ^
    

    选择哪个

    <source src="video.mp4" type="video/mp4" label="1080P" res="1080"/> 
    

    【讨论】:

    • 天哪……你是对的!!!!我想我需要在我的终端或其他东西上调高字体,8 在我眼里看起来像 0。谢谢。
    猜你喜欢
    • 2016-02-22
    • 2023-01-12
    • 2012-08-12
    • 2013-12-19
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    相关资源
    最近更新 更多