I'm getting the following error: Undefined property: DOMElement::$wholeText"
when I loop over the query and try to echo the wholeText result.
$try = $xpath->query('//h2/following-sibling::ul/li | //h2/following-sibling::h3/text()');
foreach($try as $values){
echo $values->wholeText;
//echo '<pre>', print_r($values), '</pre>';
}
The $xpath->query
returns the following when I print_r
the $values
variable from the foreach.
DOMText Object {
[wholeText] => House Data
[data] => House Data
[length] => 10
[nodeName] => #text
[nodeValue] => House Data
[nodeType] => 3
[parentNode] => (object value omitted)
[childNodes] =>
[firstChild] =>
[lastChild] =>
[previousSibling] =>
[nextSibling] =>
[attributes] =>
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] =>
[textContent] => House Data
)
DOMElement Object (
[tagName] => li
[schemaTypeInfo] =>
[nodeName] => li
[nodeValue] => 12 doors are very expensive
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => li
[baseURI] =>
[textContent] => 12 doors are very expensive
)
DOMText Object (
[wholeText] => Car Data
[data] => Car Data
[length] => 8
[nodeName] => #text
[nodeValue] => Car Data
[nodeType] => 3
[parentNode] => (object value omitted)
[childNodes] =>
[firstChild] =>
[lastChild] =>
[previousSibling] =>
[nextSibling] =>
[attributes] =>
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] =>
[textContent] => Car Data
)
DOMElement Object (
[tagName] => li
[schemaTypeInfo] =>
[nodeName] => li
[nodeValue] => The car has 4 doors
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => li
[baseURI] =>
[textContent] => The car has 4 doors
)
But if I echo $values->nodeValue;
it works, although it echo's all of the data, I'm just trying to access the wholeText individually, I don't understand why this error is popping up?
UPDATE:
Now that I took a closer look, I see that when I echo $values->wholeText;
it's trying to echo the DOMElement and not the DOMText.
How can I reference the DOMText instead of the DOMElement when echoing?