When is it OK to use an XML file to save information?

后端 未结 5 957
忘了有多久
忘了有多久 2020-12-20 18:31

What reason could there be for using an XML to save information?

5条回答
  •  执念已碎
    2020-12-20 18:53

    It's probably a good idea to invert your question: when would it not be okay to use XML to save information?

    • When you only need to append data frequently, the canonical example being log files. XML would require you to parse the whole document and find the correct position for inserting in order not to break the well-formed structure

    • When you only need to query certain items in the file frequently. XML would probably not be efficient to randomly access parts of the file. This could probably be better handled with a format that stores the frequently accessed information at a well-know offset so that parsing the file is not required.

    • When storing non-hierarchical, sequential data there are usually better alternatives to XML. Think about image, audio or video file formats.

提交回复
热议问题