domxpath

What is a multi branch xpath query for finding this?

给你一囗甜甜゛ 提交于 2020-02-08 11:37:28
问题 This is my current xpath query: //node:Expr_Assign[subNode:var/node:Expr_Variable/subNode:Name/scalar:string='my_chinese_surname' and subNode:expr/node:Scalar_String/subNode:value/scalar:string='Qiu'] I'm trying to find it in this xml: <?xml version="1.0" encoding="UTF-8"?> <AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:attribute="http://nikic.github.com/PHPParser/XML/attribute" xmlns:scalar="http://nikic.github

What is a multi branch xpath query for finding this?

时间秒杀一切 提交于 2020-02-08 11:36:05
问题 This is my current xpath query: //node:Expr_Assign[subNode:var/node:Expr_Variable/subNode:Name/scalar:string='my_chinese_surname' and subNode:expr/node:Scalar_String/subNode:value/scalar:string='Qiu'] I'm trying to find it in this xml: <?xml version="1.0" encoding="UTF-8"?> <AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:attribute="http://nikic.github.com/PHPParser/XML/attribute" xmlns:scalar="http://nikic.github

PHP XPath. How to return string with html tags?

假如想象 提交于 2020-01-24 15:59:45
问题 <?php libxml_use_internal_errors(true); $html = ' <html> <body> <div> Message <b>bold</b>, <s>strike</s> </div> <div> <span class="how"> <a href="link" title="text">Link</a>, <b> BOLD </b> </span> </div> </body> </html> '; $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->strictErrorChecking = false; $dom->recover = true; $dom->loadHTML($html); $xpath = new DOMXPath($dom); $messages = $xpath->query("//div"); foreach($messages as $message) { echo $message->nodeValue; } This

PHP DOMXPath query using the innerHTML/nodeValue of an element to find and return the element

好久不见. 提交于 2020-01-04 15:25:14
问题 Can you please help me with the correct syntax to use when you want to check the innerHTML/nodeValue of an element? I have no problem with the Name however the Age is within a plain div element, What is the correct syntax to use in place of "NOT SURE WHAT TO PUT HERE" below. $html is a page from the internet The persons name is in a span like: <span class="fullname">John Smith</span> The persons age is in a div like: <div>Age: 28</div> I have the following PHP: <?php $dom = new DomDocument();

DOMElement does not seem to be removed from DOMNodeList

点点圈 提交于 2020-01-04 05:26:46
问题 Plase, help! Need to delete 1st element from DOMNodeList $myDivs , but actual removal dosen't occur - element remains. $dom = new DOMDocument(); $dom->loadHTML($file); $xpath = new DOMXPath($dom); $myDivs = $xpath->query('//div[@data-name|data-price]'); usleep(1); //Must REVERSE iterate DOMNodeList. for ($i = $myDivs->length - 1; $i >= 0; $i--) { //Deleting 1st element of (DOMNodeList) $myDivs, containing advertisement product if ($i == 0) { //Removing div element (DOMNode) from DOM?

DOMXPath get sibling depending on previous sibling value

梦想的初衷 提交于 2020-01-04 01:27:50
问题 Let's say I have this: <foo> <bar>CCC</bar> <baz>sometexthere</baz> </foo> <foo> <bar>AAA</bar> <baz>sometext</baz> </foo> <foo> <bar>DDD</bar> <baz>something</baz> </foo> Now, I want to get the baz value, which is coming right after bar with the value AAA (!but only with the value AAA !). I don't know how many "foo"s I have, so I can't exactly write something like: $element->item(0) // I don't know the exact number So how can I get the value of the baz, which follows after bar with a

DOMxpath query returns nothing

房东的猫 提交于 2019-12-25 12:12:20
问题 I need to load, modify and output some 3rd party iframe on my webpage. As suggested, I had created the intermediary page that simply contains <iframe> with its src attribute. The php code that outputs the page looks like this: $iframe->loadHTML(file_get_contents("http://example.com/iframe_page.php")); //creating DOM object, see htm content below $xpathObj= new DOMXPath($iframe);//creating DOMXPath object foreach ($xpathObj->query('//div[@id="specific_id"]') as $node){ //this query returns

DomXPath with DOMDocument to get <img> Class URL

♀尐吖头ヾ 提交于 2019-12-25 02:59:24
问题 I am writing a little scraper script that will find the image URL that has a particular class name. I know that my cURL and DOMDocument is functioning okay, and even the DomXPath really (as far as I can tell, there are no errors) But I am struggling to work out how to get the URL of the xpath query results. My code so far: $dom = new DOMDocument(); @$dom->loadHTML($x); $xpath = new DomXpath($dom); $div = $xpath->query('//*[@class="productImage"]'); var_dump($div); echo $div->item(0); If I var

Using OR operator in XPath

会有一股神秘感。 提交于 2019-12-24 19:17:51
问题 I'm using the OR operator (more than once) in my XPath expression to extract what I need in the content before a specific string is encountered such as 'Reference,' 'For more information,' etc. Any of these terms should return the same result, yet they may not be in that order. For example, 'Reference' might not be first and may not be in the content at all, and one of the matches uses a table, 'About the data.' I want all content before any one of these strings appears. Any help would be

Check if domnodelist->item(x)->nodeValue == “nbsp;”

谁都会走 提交于 2019-12-24 02:33:08
问题 I have logged in to, and grabbed the return page using CURL , loaded it with DOMDocument and then queried it with DOMXPATH (to find 'table.essgrid tr'). (I am then also querying the result to find child 'td's and) with the results, results->item(2)->nodeValue is either a date or what echos in browser as   or . I need to check if it will be a non break space or actual text. Hopefully that makes some sense with the code below. $dom = new DOMDocument(); $dom->loadHTML($result); $xpath = new