zsljulius
zsljulius

Reputation: 4123

XML manipulation In PHP

I have question on XML Manipulation in PHP.

So I have a requirement to parse a xml file and then display it on the website, these are not difficult. But then, I will need to let the user edit the field in xml in forms. Basically, I grouped the xml file into four tables, each table has add,delete edit functionality.

The way I did it was each time the user submit the form, I open up the XML, read it in using fopen, then find the location for delete, add or edit, then store it as a new file, then delete the original file. This process works ok, but involves lots of I/O handling and if the user do the form update fast, it will simply crush, with the error, file in use or cannot find file or something.

Upvotes: 1

Views: 146

Answers (1)

alagar
alagar

Reputation: 134

Why don't you use simpleXML extension for that purpose? Maybe you should store your xml files in DB :

CREATE TABLE IF NOT EXISTS `xml` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `file` text NOT NULL,
  `isEditedNow` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

So you will just need to read the xml file from table and then (when user will modify it) just update record.

Upvotes: 1

Related Questions