Jump to content

SimpleXML Error: Node no longer exists (using addChild())


breex

Recommended Posts

Hi,

like the title says simplexml is giving me a "Node no longer exists" error while using the addChild() function. Note that it's not giving an error on the first addChild();

Can somebody help ?


[u]code causing error: [/u]

$xml = simplexml_load_file("../xml/books.xml");

if($xml) {

$book = $xml->books->addChild('book');
$book->addChild('title',$this->myTitle);                      // line 171
$book->addChild('subtitle',$this->mySubTitle);
$book->addChild('publisher',$this->myPublisher);
$book->addChild('year',$this->myYear);
$book->addChild('cover',$this->cover);
$book->addChild('cover_thumb',$this->cover_thumb);  // line 176
}



[u]xml structure:[/u]

<books>
  <book>
    <title></title>
    <subtitle></subtitle>
    <publisher></publisher>
    <year></year>
    <cover></cover>
    <cover_thumb></cover_thumb>
  </book>
</books>



[u]complete error:[/u]

Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in C:\Program Files\XAMPP\xampp\htdocs\php\Book.class.php on line 171

Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in C:\Program Files\XAMPP\xampp\htdocs\php\Book.class.php on line 172

Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in C:\Program Files\XAMPP\xampp\htdocs\php\Book.class.php on line 173

Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in C:\Program Files\XAMPP\xampp\htdocs\php\Book.class.php on line 174

Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in C:\Program Files\XAMPP\xampp\htdocs\php\Book.class.php on line 175

Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: Node no longer exists in C:\Program Files\XAMPP\xampp\htdocs\php\Book.class.php on line 176
I found the answer and post it so nobody needs to break his head over this like i did  >:(

when using simplexml_load_file() it automatically select the root-node.

So when I was doing [code]$book = $xml->books->addChild('book');[/code]

I was trying to select the root (being books) while already being on it. Thats why it gave me a "Node no longer exists" error (should have gave me something like "Node yur trying to select doesnt exist")

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.