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
Link to comment
Share on other sites

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")
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.