Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
在Bash脚本中转义单引号xmllint xpath查询_Xml_Bash_Xpath_Escaping_Xmllint - Fatal编程技术网

在Bash脚本中转义单引号xmllint xpath查询

在Bash脚本中转义单引号xmllint xpath查询,xml,bash,xpath,escaping,xmllint,Xml,Bash,Xpath,Escaping,Xmllint,我试图在bash脚本中使用xmllint从xmltv文档中查询信息,但在标题中使用单引号的节目标题时遇到了问题。例如: XML示例: <programme start="20150106090000 -0500" stop="20150106093000 -0500" channel="I53.28457646.microsoft.com"> <title lang="en">Daniel Tiger's Neighborhood</title>

我试图在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>
我试过几种方法来逃避它,包括用双引号括起来,写Tiger's和Tiger
&aposs,我尝试的似乎都没有帮助


感谢您的帮助。谢谢

在尝试了一点之后,我找到了两种方法。解决方案是在xpath
XPATHPRE“XPATHPOST
之外通过
\'
转义单引号,并将其连接起来,同时将属性/文本保持在
的周围


多亏了@EtanReisner,这一切都成功了!:

xmllint --xpath "/tv/programme[title=\"Daniel Tiger's Neighborhood\"]" xmltv.xml

您需要从名为“Daniel Tiger's Neighborary”的标记程序中获取哪些信息?使用
“/tv/program[title='Daniel Tiger's Neighborary']”“
从shell的角度来看应该是可行的,但这无助于解决内部问题。
“/tv/program[title='Daniel Tiger's Neighborary\]”“]“
可能也可行/电视/节目[title='Daniel Tiger's Neighbour']“
但这取决于xmllint和xml引用。@Cyrus游戏的最终目的是获取开始的内容=”属性,以使用“显示标题”、“说明”和“开始时间”作为匹配条件来获取原始的播放日期。这样,我就可以用Plex Media Server接收和查询TheTVDB.com信息的原始播放日期来命名录制内容。@EtanReisner这很有效!:xmllint--xpath“/tv/program[title=\“Daniel Tiger's Neighborary\”]”xmltv.xmlI刚刚尝试了这些行,结果如下:andrew@andyrblank:$xmllint--xpath'/programme/title[text()=“Daniel Tiger'\''s Neighbour”]'xmltv.xml xpath集为空andrew@andyrblank:$xmllint--xpath'/program/title[text()=“'Daniel Tiger's Neighbour'”'xmltv.xml警告:未能加载外部实体“Tiger's”警告:未能加载外部实体“Neighborhood”]“XPath错误:未完成的文字xmlXPathEval:求值失败XPath求值失败第二个建议的命令不正确。它需要是
…”“'Daniel Tiger's Neighborhood'”“…
我相信。举个简单的例子,两种解决方案都很有效。下面是我得到的:最小XML
pu'ps
和最小脚本
#/bin/bash xmllint--xpath'/foo/bar[text()=“pu'\'ps”和@title=“ke'\'ks”]'foo.xml xmllint--xpath'/foo/bar[text()=“pu''ps'”和@title=“'ke''ks'””foo.xml
。这两个命令最后都显示
pu'ps
@Etan Reisner您的解决方案也适用于我:)示例中缺少空格会导致出现问题。在你的案例中,你不需要引用这个词,但在@AndyRBlank的案例中,你需要引用。
xmllint --xpath '/programme/title[text()="Daniel Tiger'\''s Neighborhood"]' xmltv.xml
xmllint --xpath '/programme/title[text()="'Daniel Tiger\'s Neighborhood'"]' xmltv.xml
xmllint --xpath "/tv/programme[title=\"Daniel Tiger's Neighborhood\"]" xmltv.xml