adding / deleting / appending to xml

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
ja660k
Forum Newbie
Posts: 1
Joined: Sun Oct 05, 2008 3:07 am

adding / deleting / appending to xml

Post by ja660k »

is there any way to tell the xml file to put the data where i want...
eg

Code: Select all

 
<user>
    <new>
        <data></data>
    </new>
    <new>
        <data></data>
    </new>
</user>
 
because i would like to append data in between the <user> tags
because at the moment its like this

Code: Select all

 
<user>
    <new>
        <data></data>
    </new>
</user>
<user>
    <new>
        <data></data>
    </new>
</user>
 
and thats causing php to complain

Code: Select all

 
Warning: simplexml_load_file() [function.simplexml-load-file]: users.xml:30: parser error : Extra content at the end of the document in /var/www/part2/part2/php/login.php on line 11
 
Warning: simplexml_load_file() [function.simplexml-load-file]: <new> in /var/www/part2/part2/php/login.php on line 11
 
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /var/www/part2/part2/php/login.php on line 11
Fatal Error in opening xml doc
 
is there a way where i can tell it to go inside the <user> tag?
kashbridge
Forum Newbie
Posts: 2
Joined: Sun Oct 05, 2008 5:17 am

Re: adding / deleting / appending to xml

Post by kashbridge »

one thing you might want to do is include a 'user_id' number as an attribute for each <user> node, then use an XPath expression to locate the node you want to insert after.
Post Reply