I have gone through the Stack Overflow post "Best XML Parser for PH开发者_StackOverflow中文版P".
For the same question. It is mentioned that, if I need to manipulate XML files then go for DOM XML. My requirements are:
- I have saved navigation in database. It is an HTML string.
- 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 unwantedli
's, I want to save the whole string back to the database. - The same navigation will be used on another page. But, the HTML will be different. It will be similar, with the
ul
andli
, but I need to add some more divs and spans to it. 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.
Using the new structure, again build the navigation, which will be updated in the first navigation table.
Which will be best option?
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.
I'd recommend SimpleXML.
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.
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.
精彩评论