XPath help?
am 05.04.2008 18:02:38 von Mark ReedOK, not sure what I'm missing here. I'm using PHP 5.2.5. I have an
XHTML document successfully loaded into a DOMDocument object $doc
(although for some reason loadXML() complains that is not a
defined entity, even though the !DOCTYPE is pointing to an HTML DTD
that defines it). The document is navigable, with the DOM methods, I
can output it with saveXML() and all looks good, etc.
So I try to extract some nodes via XPath, and I can't find anything.
Example:
$xpath = new DOMXPath($doc);
$nodes = $xpath->query('//td');
That should find all the
>getElementsByTagName() and my Mark I eyeballs, there are eight of
those. But it returns the empty set.
$xpath->query('/') returns the document node as expected.
$xpath->query('/*') returns the html element as expected.
$xpath->query('/html') returns the empty set.
$xpath->query('//html') also returns the empty set.
No matter what element name I use, XPath won't find it if I search for
it; but if I search via wildcards and then examine the name of the
nodes I find, they match exactly the strings I'm searching for.
None of the names are qualified in the document, btw.
So I'm a little confused.
Can anyone help?
Re: XPath help?
am 05.04.2008 22:00:53 von Mark ReedOk, never mind, this was the old namespace mapping issue.
So why is it that XPath processors don't use the default namespace
information declared by the xmlns attribute of the root element?