exmple thức ăn chăn nuôi: view-source: http://rss.packetstormsecurity.org/files/tags/exploit/văn bản trận đấu với cú pháp XPath
Tôi chỉ muốn trở lại các phần của xml nơi nút tiêu đề phụ huynh đã phù hợp với văn bản trong đó, trong ví dụ này các văn bản để phù hợp là "trang web" .
//get feed with curl
$doc = new SimpleXmlElement($xml, LIBXML_NOCDATA);
//$result = $doc->xpath('//title'); //this works returns all the <title>'s
$result = $doc->xpath('//title[site]'); //doesn't work
$result = $doc->xpath('//title[text()="site"]'); //doesn't work
$result = $doc->xpath('//title[contains(site)]'); //doesn't work
$result = $doc->xpath('//title[contains(text(),'Site')]'); //doesn't work
foreach ($result as $title)
echo "$title<br />"
+1 Câu trả lời đúng. Bạn đã viết * "chúng tôi đang sử dụng nút hiện tại" *. Nhưng hàm 'fn: contains()' mong đợi hai đối số kiểu dữ liệu chuỗi, vì vậy cú pháp viết tắt 'self :: node()' ('.') sẽ được đúc bằng hàm' fn: string() ', trả về chuỗi ** value **: nối tất cả các nút văn bản con cháu. –