带有PHP的Xpath-特殊字符和转义符

时间:2019-01-28 09:25:15

标签: php xpath

我正在使用Xpath:

$xpath = "//*[@class='title-link color-p4'][@name='Result_1'][@id='Result_1'][@href='http://eds.b.ebscohost.com/eds/viewarticle/render?data=dGJyMPPp44rp2%2fdV0%2bnjisfk5Ie46a9Jsqa1TbOk63nn5Kx94um%2bSa2otkewpq9Rnqe4S7GwsE%2bet8s%2b8ujfhvHX4Yzn5eyB4rOrSberrk2vqa5Nrpzqeezdu33snOJ6u9e3gKTq33%2b7t8w%2b3%2bS7SbGqr0q0qbdKpNztiuvX8lXk6%2bqE8tv2jKTd833x6rts8Ovj&vid=11&sid=b5ffad10-8cea-40ed-957d-4153b7209717@sessionmgr101'][@onclick='__doLinkPostBack('','target~~fulltext||args~~1','');return false;'][@title='Bulk defects and surface state dynamics in topological insulators: The effects of electron beam irradiation on the ultrafast relaxation of Dirac fermions in Bi2Te3. '][@accesskey='1']";

应该匹配以下元素:

<a class="title-link color-p4" name="Result_1" id="Result_1" href="http://eds.b.ebscohost.com/eds/viewarticle/render?data=dGJyMPPp44rp2%2fdV0%2bnjisfk5Ie46a9Jsqa1TbOk63nn5Kx94um%2bSa2otkewpq9Rnqe4S7GwsE%2bet8s%2b8ujfhvHX4Yzn5eyB4rOrSberrk2vqa5Nrpzqeezdu33snOJ6u9e3gKTq33%2b7t8w%2b3%2bS7SbGqr0q0qbdKpNztiuvX8lXk6%2bqE8tv2jKTd833x6rts8Ovj&amp;vid=11&amp;sid=b5ffad10-8cea-40ed-957d-4153b7209717@sessionmgr101" onclick="__doLinkPostBack('','target~~fulltext||args~~1','');return false;" title="Bulk defects and surface state dynamics in topological insulators: The effects of electron beam irradiation on the ultrafast relaxation of Dirac fermions in Bi2Te3. " accesskey="1">Bulk defects and surface state dynamics in topological insulators: The effects of electron beam irradiation on the ultrafast relaxation of Dirac fermions in Bi2Te3. </a>

但是

$xpatho = new DOMXpath($doc);

            $elementsn =  $xpatho->query($xpath);

$ elementsn-> length给我0。

是因为属性名称/值中包含一些特殊字符吗?一般来说,一个人必须在xpath中转义哪些特殊字符,以及如何做到?

注意:我正在使用PHP 7.1.22。

0 个答案:

没有答案