I have a javascript popup that "successfully" employs php to load another page as a DOMDocument and "successfully" finds a element by id to display its text using nodeValue...BUT...the nodeValue call returns NOT the text inside the desired element but the text inside an anchor tag with the same name. Here's some of the code:
the html and php that seemingly "works":
<span style="position:relative;"><span id="favelas" class="popup">
<?php
// Create a new DOMDocument object
$doc = new DOMDocument;
// enable user error handling
libxml_use_internal_errors(true);
// Validate our document before referring to the id
$doc->validateOnParse = true;
// Load the key terms and identifications html file
$doc->loadHtml(file_get_contents('http://teachers.dadeschools.net/jzoeller/APHG/0-Key-Terms-Identifications.html'));
// Print in readable form the content the element by id
print_r($doc->getElementById('favela')->nodeValue);
?>
</span><a href="javascript:void(null);" onMouseover="ShowPop('favelas');" onMouseout="HidePop('favelas');">favelas</a></span>
Now, what "should" be displayed is the definition of the term favela from the page referenced in the code above. What I'm getting is merely the word "favela".
Here's some more code, this time from the page loaded by the php:
<tr>
<td><a name="favela">
favela</a></td>
<td class="def" id="favela">A shantytown or slum, especially in Brazil.</td>
<td>07</td>
<td>06</td>
</tr>
Debugging with var_dump gives me this:
object(DOMElement)#1 (17) { ["tagName"]=> string(1) "a" ["schemaTypeInfo"]=> >NULL ["nodeName"]=> string(1) "a" ["nodeValue"]=> string(8) " favela" >["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" >["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) >"(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" >["previousSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" >["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL >["prefix"]=> string(0) "" ["localName"]=> string(1) "a" ["baseURI"]=> NULL >["textContent"]=> string(8) " favela" }
This seems to be saying that its got the anchor named "favela" and NOT the td named "favela". What gives?!
nameattribute of anaelement is an ID attribute (the ID attribute does not need to have the nameid). As of that you will find thea. - t.niese//[@id='favela']but as I said, I don't knowDOMDocumentthat well, so iI neither know if my assumption is really correct, nor if@idwill suffer from the same problem. - t.niese