Jump to content


Photo

Editting XML Files with PHP


  • Please log in to reply
2 replies to this topic

#1 Zipp425

Zipp425
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 12 September 2006 - 12:44 AM

Ive been working on a way to edit an xml file, I have been using fopen and just specifying a specific line to replace, but that wasnt working very well, because sometimes lines seemed to be off, or users would give data that would cause line breaks.

I just recently learned about SimpleXML in PHP5, and I was wondering if someone could explain to me how I could use PHP to open a XML file, and select a specific tag name and replace a specific attribute, or a array of attributes.

I would be using xmlHttpRequest to pass data to the PHP file that would then open and edit the XML file.

Thanks for your help in advance

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 12 September 2006 - 06:55 AM

see example 7

http://www.php.net/m...f.simplexml.php
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Zipp425

Zipp425
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 12 September 2006 - 12:53 PM

Beautiful. Thank you very much.

Now, do you know if there is a way to make it so it will only create the new file once, and later just edit the created file?

I would like to have one standard XML file that is then editted by user select and saved to a different XML file according to their userid

IE
standard.xml
--User Changes default settings
---new attributes saved as userid.xml
----User changes more settings
-----edit attributes in userid.xml

Nevermind, unless im wrong it looks like you can specify a file to write to with asXML()

Thanks for your help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users