...

View Full Version : how to extract a tag with a class name's innerhtml



gilgalbiblewhee
03-18-2010, 10:22 PM
I need to get the innerHTML of the maintext class name of a table tag.
If I use:

$dom = new SimpleXMLElement(file_get_contents($file));//line 87
$tables = $dom->xpath('//table[@class="maintext"]');
print_r($tables);
I get:


Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: meta line 1 and head in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: link line 1 and head in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: =utf-8"></head><link rel="stylesheet" type="text/css" href="/style5.css"></head> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : AttValue: " or ' expected in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: adding="0" align="center" class="tablebk"><tr><td valign="middle"><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : attributes construct error in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: adding="0" align="center" class="tablebk"><tr><td valign="middle"><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Couldn't find end of Start Tag iframe line 1 in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: adding="0" align="center" class="tablebk"><tr><td valign="middle"><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: td line 1 and iframe in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: src="/sections/genesis/1-1.htm" align=left frameborder=0 cellpadding=0></iframe> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: tr line 1 and td in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: /sections/genesis/1-1.htm" align=left frameborder=0 cellpadding=0></iframe></td> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: table line 1 and tr in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ions/genesis/1-1.htm" align=left frameborder=0 cellpadding=0></iframe></td></tr> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : AttValue: " or ' expected in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: tr><tr valign="middle" class="topbk"><td height="24" align="center" cellpadding= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : attributes construct error in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: tr><tr valign="middle" class="topbk"><td height="24" align="center" cellpadding= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Couldn't find end of Start Tag td line 1 in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: tr><tr valign="middle" class="topbk"><td height="24" align="center" cellpadding= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : AttValue: " or ' expected in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: e width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : attributes construct error in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: e width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Couldn't find end of Start Tag iframe line 1 in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: e width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: td line 1 and iframe in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: no src="/menus/genesis/1-1.htm" align=left frameborder=0 cellpadding=0></iframe> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: tr line 1 and td in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: c="/menus/genesis/1-1.htm" align=left frameborder=0 cellpadding=0></iframe></td> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: table line 1 and tr in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: enus/genesis/1-1.htm" align=left frameborder=0 cellpadding=0></iframe></td></tr> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : AttValue: " or ' expected in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: align="center"><tr align="center" valign="middle"><td height="90"><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : attributes construct error in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: align="center"><tr align="center" valign="middle"><td height="90"><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Couldn't find end of Start Tag iframe line 1 in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: align="center"><tr align="center" valign="middle"><td height="90"><iframe width= in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: td line 1 and iframe in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: eight=90 scrolling=no src="/topmenu30.htm" frameborder=0 cellpadding=0></iframe> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: tr line 1 and td in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: =90 scrolling=no src="/topmenu30.htm" frameborder=0 cellpadding=0></iframe></td> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: table line 1 and tr in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: crolling=no src="/topmenu30.htm" frameborder=0 cellpadding=0></iframe></td></tr> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: td line 1 and table in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: =no src="/topmenu30.htm" frameborder=0 cellpadding=0></iframe></td></tr></table> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: tr line 1 and td in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: rc="/topmenu30.htm" frameborder=0 cellpadding=0></iframe></td></tr></table></td> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: body line 1 and table in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: 0.htm" frameborder=0 cellpadding=0></iframe></td></tr></table></td></tr></table> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: head line 1 and td in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: " frameborder=0 cellpadding=0></iframe></td></tr></table></td></tr></table></td> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ... \ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Opening and ending tag mismatch: html line 1 and tr in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: meborder=0 cellpadding=0></iframe></td></tr></table></td></tr></table></td></tr> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Extra content at the end of the document in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: meborder=0 cellpadding=0></iframe></td></tr></table></td></tr></table></td></tr> in ...\ins_conc_indb.php on line 87

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ...\ins_conc_indb.php on line 87

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in ...\ins_conc_indb.php:87 Stack trace: #0 ...\ins_conc_indb.php(87): SimpleXMLElement->__construct('???<html><head>...') #1 {main} thrown in ...\ins_conc_indb.php on line 87

On the other hand if I use:
DOMElement

//SimpleXMLElement
$dom = new DOMElement(file_get_contents($file)); // line 88
$table = $dom->xpath('//table[@class="maintext"]');
print_r($table);
I get:

Fatal error: Uncaught exception 'DOMException' with message 'Invalid Character Error' in ...ins_conc_indb.php:88 Stack trace: #0 ...ins_conc_indb.php(88): DOMElement->__construct('???<html><head>...') #1 {main} thrown in ...ins_conc_indb.php on line 88

Dormilich
03-19-2010, 01:01 PM
first, there is no innerHTML property in the DOM, second, your XML is invalid, thus it can’t be loaded.

ah, yes, and an HTML file is loaded via DOMDocument’s loadHTML()/loadHTMLFile() method.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum