Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

xml

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

like image 394
Sergio Tapia Avatar asked Jun 23 '10 23:06

Sergio Tapia


People also ask

Why XML is used for storing data?

XML Separates Data from HTML When displaying data in HTML, you should not have to edit the HTML file when the data changes. With XML, the data can be stored in separate XML files. With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page.

Can XML be used to store data?

You can use XML to store data in files or in databases. You can write applications to store and retrieve information from the store and use generic applications to display the data.

What is XML and why it is used?

XML stands for eXtensible Markup Language. It's a language that's used to describe data. Data stored in XML is known as being "self-defining." This means that the structure of the data is embedded within the data itself.


2 Answers

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.
like image 186
Rob Levine Avatar answered Sep 26 '22 07:09

Rob Levine


It's a portable, parsable standard.

So if you have data that needs to be read by several different programs (and possibly people) you could use XML.

It is also relatively easy to validate and transform (via XSLT) into other formats.

Obviously you could use other formats, but that doesn't stop you using XML.

like image 44
ChrisF Avatar answered Sep 23 '22 07:09

ChrisF