DOMDocument->getElementById() isn't working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is the input string I'm using:

<div id="custom">
  <table width="100%" cellspacing="0" cellpadding="10">
    <tbody>
      <tr valign="top">
        <td id="frame1" style="width:30%;height:80%">
          <div id="display">
            <div id="toolBYOPPageMetaData3">
              {display ref="BYOPPageMetaData" id="3"}
            </div>
          </div>
        </td>
        <td id="frame2" style="width:70%;height:80%">
          <div id="display">
            <div id="toolResourceList0">
              {display ref="ResourceList" id="0"}
            </div>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
</div>


And here is the PHP stub I'm using:

  $oDOMDocument = new DOMDocument;
  $oDOMDocument->preserveWhiteSpace = false;
  $oDOMDocument->formatOutput = true;
  $oDOMDocument->validateOnParse = true;

  if( $oDOMDocument->loadHTML( $cleanedFile ))
  {
    $aLayoutNodes = $oDOMDocument->getElementsByTagName("div");
    if( 0 < count( $aLayoutNodes ))
    {
      echo 'Found [' . count( $aLayoutNodes ) . '] nodes.' . "\n";
      foreach( $aLayoutNodes as $oLayoutNode )
      {
        $sLayoutId = $oLayoutNode->getAttribute( 'id' );
        echo 'Current Id: [' . $sLayoutId . ']' . "\n";

      }
    }

    $oCustomNode = $oDOMDocument->getElementById( "custom" );
    echo 'Tag: ' . $oCustomNode->nodeValue . "\n";

  }


Getting the elements by tag name, while iterating through the list I see
that one of the nodes has an id of 'custom'.  However, when I try to get the
element directly using getElementById(), it doesn't return the node
properly.  Am I doing something wrong?

Also, as an aside, one thing that I found odd is that count( $aLayoutNodes )
shows as 1 even though more are found.  Huh?

thnx,
Christoph

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux