【发布时间】:2015-01-13 16:30:35
【问题描述】:
我正在尝试使用 bash 脚本中的 xmllint 从 xmltv 文档中查询信息,但我遇到了标题中包含单引号的程序标题的问题。例如:
XML 示例:
<programme start="20150106090000 -0500" stop="20150106093000 -0500" channel="I53.28457646.microsoft.com">
<title lang="en">Daniel Tiger's Neighborhood</title>
<sub-title lang="en">Safety Patrol; Safety at the Beach</sub-title>
<desc lang="en">Prince Tuesday visits the school in his crossing guard uniform and helps the children practice safety rules; Daniel and Katerina drift too far from Mom while playing at the beach.</desc>
<credits>
<actor>Jake Beale</actor>
<actor>Ted Dykstra</actor>
<actor>Heather Bambrick</actor>
<actor>Amariah Faulkner</actor>
<actor>Stuart Ralston</actor>
<actor>Zachary Bloch</actor>
<actor>Addison Holley</actor>
<actor>Nicholas Kaegi</actor>
</credits>
<date>20130715</date>
<category lang="en">Children</category>
<category lang="en">Educational</category>
<category lang="en">Episodic</category>
<category lang="en">Kids</category>
<category lang="en">Series</category>
<episode-num system="onscreen">130</episode-num>
<episode-num system="ms_progid">1.EP015507510029</episode-num>
<episode-num system="dd_progid">EP01550751.0029</episode-num>
<video>
<aspect>16:9</aspect>
<quality>HDTV</quality>
</video>
<audio>
<stereo>stereo</stereo>
</audio>
<previously-shown start="20130715000000" />
<subtitles type="teletext" />
<rating system="VCHIP">
<value>TV-Y</value>
</rating>
</programme>
xmllint 行:
xmllint --xpath '/tv/programme[title='Daniel Tiger's Neighborhood']' xmltv.xml
我尝试了几种方法来尝试转义它,包括用双引号括起来并写下 Tiger's 和 Tiger&apos;s,但我尝试的任何方法似乎都没有帮助。
感谢任何帮助。谢谢!
【问题讨论】:
-
您需要从标题为“Daniel Tiger's Neighborhood”的标签程序中获得哪些信息?
-
使用
"/tv/programme[title='Daniel Tiger's Neighborhood']"从shell 的角度来看应该可以工作,但这无助于解决内部问题。"/tv/programme[title=\"Daniel Tiger's Neighborhood\"]"可能会起作用,"/tv/programme[title='Daniel Tiger\'s Neighborhood']"可能也会起作用,但这取决于 xmllint 和 xml 引用。 -
@Cyrus 最终的游戏是获取之前显示的标签中的 start="" 属性的内容,以使用节目标题、描述和开始时间作为我的匹配条件来获取原始播出日期.这样我就可以用 Plex Media Server 的原始播放日期命名录音,以便获取和查询 TheTVDB.com 信息。
-
@EtanReisner 这有效!:xmllint --xpath "/tv/programme[title=\"Daniel Tiger's Neighborhood\"]" xmltv.xml
标签: xml bash xpath escaping xmllint