Having problems with XMLDocument

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

 



What is wrong with the following code?  It's throwing a DOMException
when I try to set the id attribute for the $lvl1Node but I can't see
why...

  $doc = new DOMDocument('1.0', 'UTF-8');
  $root = $doc->appendChild( $doc->createElement( 'root' ));
  for( $a = 0; $a <= 3; $a++ )
  {
    $lvl_1_id = 'level_1_' . $a;

    $lvl1Node = $root->appendChild( $doc->createElement( 'child', $lvl_1_id ));
    $lvl1Node->setIdAttribute( 'id', $lvl_1_id );

  }

  for( $b = 0; $b <= 3; $b++ )
  {
    $lvl_1_id = 'level_1_' . $b;
    $lvl_2_id = 'level_2_' . $b;

    $oElTmp = $doc->getElementById( $lvl_1_id );
    if( $oElTmp )
    {
      $lvl2Node = $oElTmp->appendChild( $doc->createElement( 'child',
$lvl_2_id ));
      $lvl2Node->setIdAttribute( 'id', $lvl_2_id );

    }
    else
    {
      echo 'Could not find element with id [' . $lvl_1_id . ']<br>';

    }
  }

  echo '<pre>' . htmlentities( $doc->saveXML()) . '</pre>';


Any pointers would be greatly appreciated.

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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