Jump to content

XPATH Question


twittoris

Recommended Posts

I am having trouble obtaining the second table in this HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><html> 
<head> 
<meta http-equiv="Pragma" content="no-cache"> 
<title>Entity Information</title> 
<link rel="stylesheet" href="documents/CORP/default.css" media="screen" type="text/css"> 
<link rel="stylesheet" href="documents/CORP/infotable.css" media="screen" type="text/css"> 
</head> 
<body> 
<div class="headings"> 
<h1 class="dos_heading1">Company Information </h1> 
<BR> 
<h2 class="dos_heading2"> </h2> 
<h3 class="page_heading">Company Information</h3> 
<p class="DtMsg">The information contained in this database is current through September 10, 2010.</p> 
</div> 
<hr noshade width="100%"> 
<center> 
<div class="highlight">Selected Company Name: 1 PARK ROW, LLC</div> 
      <table summary="This table contains status information for the selected entity."> 
         <caption> 
         Selected Company Status Information
         </caption> 
         <tr> 
            <th>Current Company Name:</th> 
            <td>1 PARK ROW, LLC</td> 
         </tr> 
         <tr> 
            <th>Initial  Filing Date:</th> 
            <td>JANUARY   22, 1997</td> 
         </tr> 
         <tr> 
            <th>County:</th> 
            <td>NASSAU</td> 
         </tr> 
         <tr> 
            <th>Jurisdiction:</th> 
            <td>NEW JERSEY </td> 
         </tr> 
         <tr> 
            <th>Entity Type:</th> 
            <td>DOMESTIC LIMITED LIABILITY COMPANY</td> 
         </tr> 
         <tr> 
            <th>Current Company Status:</th> 
            <td>ACTIVE
</td> 
         </tr> 
      </table> 
<BR> 
<table id="tblAddr" summary="This table contains address information for the selected entity."> 
<caption>Selected Entity Address Information</caption> 
<tr> 
<th scope="col" id="c1" class="leftalign"><span class="rmvbold">Address</span></th> 
</tr> 
<tr> 
<td headers="c1"> 
C/O ELECTRONICS INC.<br> 
2355 PARK ROW<br> 
NEW BRUNSWICK, NEW YORK, 15538
</td> 
</tr> 
<tr> 
<th scope="col" id="c4" class="leftalign">Registered Agent</th> 
</tr> 
<tr> 
<td headers="c1"> 
NONE
</td> 
</tr> 
</table> 
<br> 
<p style="width:50%"> </p>      
<div id="divStockContainer"> 
         <h4 id="capStock">*Stock Information</h4> 
         <div id="divStock"> 
            <table id="tblStock" cellpadding="0" cellspacing="6"> 
               <tr> 
                  <th># of Shares</th> 
                  <th>Type of Stock</th> 
                  <th>$ Value per Share</th> 
               </tr> 
            <tr> 
               <td> </td> 
               <td>No Information Available</td> 
               <td> </td> 
            </tr> 
           </table> 
         </div> 
         <p id="pStockBlurb">*Stock information is applicable to domestic business corporations.</p> 
  </div> 
  <div id="divHistNmContainer"> 
         <h4 id="capNmHist">Name History</h4> 
         <div id="divNmHist"> 
            <table id="tblNameHist" cellpadding="0" cellspacing="6"> 
               <tr> 
                  <th class="FileDt">Filing Date</th> 
                  <th class="NameType">Name Type</th> 
                  <th class="CorpName">Company Name</th> 
               </tr> 
            <tr> 
               <td class="FileDt">JAN 22, 1997</td> 
               <td class="NameType">Actual</td> 
               <td class="CorpName">1 PARK ROW, LLC</td> 
            </tr> 
           </table> 
         </div> 
    <p id="pFictName"> </p> 
      </div> 
</center> 
</body> 
</html> <script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script></script>

 

 

I can get the top part with this:

/*** a new dom object ***/ 
    $dom = new domDocument; 

    /*** load the html into the object ***/ 
    $dom->loadHTML($html2); 

    /*** discard white space ***/ 
    $dom->preserveWhiteSpace = false; 

    /*** the table by its tag name ***/ 
    $tables = $dom->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 

    /*** loop over the table rows ***/ 
    foreach ($rows as $row) 
    { 
        /*** get each column by tag name ***/ 
	$cols = $row->getElementsByTagName('td');
        /*** echo the values ***/ 
        echo $cols->item(0)->nodeValue.'<br />'; 
        echo $cols->item(1)->nodeValue.'<br />'; 
        echo $cols->item(2)->nodeValue; 
        echo '<hr />'; 
    }

}

 

 

Any help would be appreciated I dont even know where to start to echo the 2nd table in the html. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/213430-xpath-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.