php - DomXML xpath what do I do next? -


i have code:

$reader = new domdocument(); $reader->loadhtml($shell); $xpath = new domxpath($reader); $xpath->registernamespace('html','http://www.w3.org/1999/xhtml'); $res = $xpath->query('descendant-or-self::*[contains(@class,"content")]'); print_r($res); 

$shell variable containing following html code:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8" />         <meta http-equiv="content-language" content="en-us" />          <title>hello world</title>     </head>      <body>         <div class="content">             hello world!!         </div>     </body> </html> 

if correct xpath query:

descendant-or-self::*[contains(@class,"content")] 

is supposed div class "content". when print array see empty object:

domnodelist object ( ) 

does mean query didnt work? domxpath query language different simplexml xpath one, because query works simplexml?

if working how view , modify matched nodes?

print_r - ing domnodelist (or of dom-classes) doesn't good: they're implemented @ c / libxml2 level, , not natively exposed php. far can tell, work, add after query, , see if results:

foreach($res $node){         var_dump($node->ownerdocument->savexml($node)); } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -