Page 1 of 1

DOM Hell

Posted: Fri Jun 29, 2007 3:22 am
by alex.barylski

Code: Select all

$arr = $this->_dom->getElementsByTagName('group');
$obj = $arr->item(0); // Get the first group Node?

$tmp = $obj->createElement('item');
//$tmp->setAttribute($name1, $value1);
//$tmp->setAttribute($name2, $value2);
//$obj->appendChild($tmp);
Here is the error I am getting:

Code: Select all

Fatal error: Call to undefined method DOMElement::createElement() in
The XML file looks something like:

Code: Select all

<package>
  <group>

  </group>
  <group>

  </group>
</package>
According to the docs item() is supposed to return DOMNode but when I print_r() it's DOMElement which is why I assume the funciton is failing...

Can anyone see anything obviously wrong with the code?

Posted: Fri Jun 29, 2007 3:31 am
by volka
Hockey wrote:Here is the error I am getting:

Code:
Fatal error: Call to undefined method DOMElement::createElement() in
createElement() is a method of DOMDocument not DOMElement.
Hockey wrote:According to the docs list() is supposed to return DOMNode but when I print_r() it's DOMElement which is why I assume the funciton is failing...

Code: Select all

<?php
$a = new DOMDocument;
var_dump($a instanceof DOMNode);
prints bool(true)DOMElement is a DOMNode.

Posted: Fri Jun 29, 2007 4:18 am
by alex.barylski
I think I figured it out...although I am still confused as hell. :P