<h3>Contact Information</h3> To Apply : Please send your CV and cover
letter to DAIIDEANEW2012@gmail.com include Grants Manager - Jalalabad
in the subject line of the application.
如何在节点之后选择文字?我有以下代码,但这不起作用。
$email = $xmlPageXPath->query('//*[preceding-sibling::h3[text()="Contact Information"]]');
$tag="contactinformation";
$XML.=createXMLtags($tag,nodelist2string($email));
答案 0 :(得分:0)
您尝试的此XPath将仅返回元素,不包括您感兴趣的文本节点:
//*[preceding-sibling::h3[text()="Contact Information"]]
您可以使用text()
来选择文本节点,例如:
//text()[preceding-sibling::h3[.="Contact Information"]]
答案 1 :(得分:0)
搜索标题,并返回第一个以下文本节点。
//h3[.="Contact Information"]/following-sibling::text()[1]
如果有东西包裹这两个标签,例如。喜欢在
<div>
<h3>Contact Information</h3> To Apply : Please send your CV and cover
letter to DAIIDEANEW2012@gmail.com include Grants Manager - Jalalabad
in the subject line of the application.
</div>
查询此div和直接文本子项可能更合理:
//div[h3="Contact Information"]/text()