I have this 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 is just a variable containing the 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 I am correct the xpath query:
descendant-or-self::*[contains(@class,"content")]
is supposed to get the div with the class "content". However when I print the array all I see is an empty object:
DOMNodeList Object
(
)
Does this mean that the query didnt work? Is the DomXPath query language different to the SimpleXML Xpath one, because the query works with SimpleXML?
If it is working how do I view and modify the matched nodes?