-2

Possible Duplicate:
A simple program to CRUD node and node values of xml file

Hi i have xml file with following attributes

<user>
 <info>
  <id>XXXXXX</id>
 </info>
</user>

I want to replace user id every time when the page loads and then save file with new id, the variable which gets id from user is $uid.

Community
  • 1
  • 1
Hasnain Aali
  • 87
  • 2
  • 16
  • 1
    read `DOMDocument` ( http://php.net/manual/en/class.domdocument.php ) or `SimpleXML` ( http://php.net/manual/en/book.simplexml.php ) manual. – Raptor Feb 26 '12 at 15:26
  • If this is all the xml within the file would it not be easier to have a template with a placeholder then you can use simple `str_replace` to insert the values then replace the file, else you would need to xpath the node and then rebuild the xml – Lawrence Cherone Feb 26 '12 at 15:33
  • Sorry! but as a beginner theses terms are bit advance for me it would be more easy if you can post the code here related to example above thanks. – Hasnain Aali Feb 26 '12 at 15:45

1 Answers1

1

Use SimpleXML

  • load the file with $xml = simplexml_load_file('filename')
  • manipulate the value in $xml
  • save the output of $xml->asXML();
Alex
  • 32,506
  • 16
  • 106
  • 171