问题描述
我正在尝试使用条件过滤器使用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
我的语法有误吗?
P.S。我系统上的libxml版本是20904
解决方法
//source[@res='1000']
不选择任何内容,因为您的文档没有这样的source
元素。
也许你是说
//source[@res='1080']
^
选择
<source src="video.mp4" type="video/mp4" label="1080P" res="1080"/>