Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    how to extract a tag with a class name's innerhtml

    I need to get the innerHTML of the maintext class name of a table tag.
    If I use:
    PHP Code:
    $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
    PHP Code:
    //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
    Compare bible texts (and other tools):
    TheWheelofGod

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,395
    Thanks
    13
    Thanked 353 Times in 349 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •