DOM Hell

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

DOM Hell

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I think I figured it out...although I am still confused as hell. :P
Post Reply