开发者

Which is the best option, SimpleXml or XML Parser in PHP?

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:

  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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜