2

我正在尝试使用 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,但我尝试的任何方法似乎都没有帮助。

任何帮助表示赞赏。谢谢!

4

2 回答 2

2

感谢@EtanReisner 这有效!:

xmllint --xpath "/tv/programme[title=\"Daniel Tiger's Neighborhood\"]" xmltv.xml
于 2015-01-13T21:11:29.263 回答
1

尝试了一下后,我发现了两种方法。\'解决方案是通过xpath 外部转义单引号XPATHPRE''XPATHPOST并将其连接起来,同时保持属性/文本围绕".

xmllint --xpath '/programme/title[text()="Daniel Tiger'\''s Neighborhood"]' xmltv.xml
xmllint --xpath '/programme/title[text()="'Daniel Tiger\'s Neighborhood'"]' xmltv.xml
于 2015-01-13T17:32:51.227 回答