Page 1 of 1

adding / deleting / appending to xml

Posted: Sun Oct 05, 2008 3:09 am
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?

Re: adding / deleting / appending to xml

Posted: Sun Oct 05, 2008 5:21 am
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.