tags:

views:

66

answers:

4

I have gone through the Stack Overflow post "Best XML Parser for PHP".

For the same question. It is mentioned that, if I need to manipulate XML files then go for DOM XML. My requirements are:

  1. I have saved navigation in database. It is an HTML string.
  2. I want to remove some pages or say li tags wrapping pages that user don't want to exist in his/her page. After removing the unwanted li's, I want to save the whole string back to the database.
  3. The same navigation will be used on another page. But, the HTML will be different. It will be similar, with the ul and li, but I need to add some more divs and spans to it.
  4. The navigation will be edited on this page and on each change (e.g. Changing page title, deleting a node/page, moving under another page as child.) a Ajax call will save the changes to another table in database.

  5. Using the new structure, again build the navigation, which will be updated in the first navigation table.

Which will be best option?

A: 

I'd recommend SimpleXML.

shamittomar
Will it be able to handle the tags with classes and inline styles ?
KutePHP
A: 

My personal preference is XML Parser but I think that the library you choose probably will not affect the solution that much. The usages of any XML manipulation library is probably largely the same.

paullb
A: 

For larger files you will want to use XML Parser because Simple XML will load the entire XML into memory to parse it whereas XML parser is stream based.

Chris
+1  A: 

For your use case, using XMLParser does not make much sense since you want to save back the whole file after modifying it. SimpleXML lets you do that much easier (saveXML() method) - with XMLReader you would have to generate the XML on your own during parsing.

cweiske