Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML or own-format file?

Tags:

file

xml

When is a good idea to save information in a XML file and when in a own-format file?

For XML (or other standard) I see:

  • (+) Standard format.
  • (-) It's tedious to hand modify.

For own-format files I see:

  • (-) We need to build a own-parser (non-standard).
  • (+) It can be easy to hand modify the files.
like image 444
FerranB Avatar asked Mar 13 '26 06:03

FerranB


2 Answers

Use XML when it's a good fit in various ways:

  • Need to share between different applications which are all capable of handling XML
  • Natural tree-like structure
  • Primarily data easily represented as text (binary data is a bit of a kludge in text-based formats)
  • Extensibility is important
  • Performance isn't critical (parsing XML isn't exactly blazingly fast - although if performance is important and you go for XML, shop around for a fast parser, as there's a wide difference between fastest and slowest)
  • Schema can be pre-defined and documents can be verified against it
  • Simpler formats (e.g. name=value pairs) don't cut it

Basically if there's a pretty natural representation of your data model in XML, that may well be the easiest way of handling it. If you'd end up having to mess around a lot to fit it in with XML, think about other formats. Note that there are plenty of other standard (or "somewhat standard" - e.g. supported by tools on multiple platforms) formats available beyond just XML.

like image 162
Jon Skeet Avatar answered Mar 16 '26 04:03

Jon Skeet


For XML I see:

  • (+) Standard format.
  • (-) It's tedious to hand modify.

    I only use XML when the API requires it.

For JSON/YAML I see:

  • (+) Standard format.
  • (+) It's easy to hand-modify.

    I use JSON/YAML for almost everything. Except when an interface requires something else.

For CSV I see:

  • (+) Standard format.
  • (+) It's easy to hand-modify.
  • (-) It's a little murky when the column names are screwy or data isn't in simple first-nromal form.

    I use CSV whenever possible.

For Language Serializers I see:

  • (+) Standard format for the given language.
  • (-) nearly impossible to hand-modify.

    I use serialized files once in a while to pass data among processes when I'm sure both sides are in the same language.

For own-format files I see:

  • (-) We need to build a own-parser (non-standard).
  • (+) It can be easy to hand modify the files.

    I avoid inventing my own file format. Haven't invented my own file format in years.

like image 34
S.Lott Avatar answered Mar 16 '26 05:03

S.Lott