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

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

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

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

    There could be lots of reasons: like any other file format, it has pros and cons:

    Pros:

    • .Net natively supports serializing your objects to xml, and deserializing them back again.
    • It is more readable and descriptive to the human eye than a binary format or JSON
    • It is easily validated against a schema to ensure it is in the correct format.
    • It can be loaded and parsed with other tools.
    • It is easily interchangeable with other platforms/languages, unlike the native .Net binary serialization format
    • It can be transformed, and you can run xpath over it.

    Cons:

    • It is more verbose than either the native .Net binary serialization format, or JSON
    • It doesn't store type information about the classes that were deserialized into xml, whereas a the native binary format does.

提交回复
热议问题