DOMDocument/DOMElement problem
| From: | Peter Lind | Date: | Tue, 16 Nov 2010 12:01:32 +0000 |
| Subject: | DOMDocument/DOMElement problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-309501@lists.php.net to get a copy of this message | ||
I'm currently trying to parse a document with DOMDocument, and I'm
having some serious problems. I created a script that runs fine on php
5.2.9, ripping out content using DOMNode::nodeValue. The same script
fails to get any content on php 5.3.3 - even though it correctly
navigates to the proper nodes to extract content.
Basically, the code used looks like this:
$dom = new DOMDocument();
$dom->loadHTML($data);
$dom->preserveWhiteSpace = false;
$xpath = new DOMXpath($dom);
$nodelist = $xpath->query($query);
$value = $nodelist->item(0)->nodeValue;
I've checked to make sure that item(0) is in fact a node - it's there
and even of the right type (a td - table cell), but nodeValue is
empty.
The script works on some documents but not others (on 5.3.3 - some
checking suggests a doctype of xhtml might be involved in the problem
but I tried ripping the doctype out and had no difference) - on 5.2.9
it works on all documents, returning the proper nodeValue.
Am I missing something basic?
TIA
Peter
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>