hm2k/Services_Mailman — Issue #8: Migrating from regex to XML parsing
Author: hm2k
Created: 2012-01-27 08:50:18+00:00
State: open

Leading on from [till's suggestion](https://github.com/till/Services_Mailman/commit/30aa0bf35d913872c18177ac0732eb67ec57799f#commitcomment-906700) I thought I would start an issue tracker for this.

I've decided to start migrating the code from regex to XML parsing after discovering XPath and benchmarking it (It's about 4 times quicker).

However, the code doesn't seem to be performing quite as expected.

I've pushed some [html for testing](https://github.com/hm2k/Services_Mailman/commit/810ab8491bda03a69b873ea9d829bca421776740).

Here's what I tried:

`preserveWhiteSpace = false;
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$email = $xpath->query('/html/body/form/center[1]/table/tbody/tr[3]/td[2]/a');
var_dump($email);
//echo $email->textContent; //Undefined property: DOMNodeList::$textContent
//echo $email->item(0)->textContent; //Trying to get property of non-object
//echo $email->nodeValue; //Undefined property: DOMNodeList::$nodeValue
//echo $email->item(0)->nodeValue; //Trying to get property of non-object
libxml_clear_errors();

?>`

I know the path is correct as when I do $x("/html/body/form/center[1]/table/tbody/tr[3]/td[2]/a'") in Chrome's console, it returns the correct tag.

I can't get my head around this...