XML for configuration files, why?

Why do so many projects use XML for configuration files?

+43
xml configuration-files methodology
Apr 26 '09 at 22:53
source share
12 answers

Thank you for your responses. This question, as naive as it might seem at first glance, was not so naive :)

Personally, I don’t like XML for configuration files, I find it difficult for people to read and modify, and for computers it is difficult to parse because they are so versatile and powerful.

INI files or Java-based files are great only for the most basic applications that require an attachment. General solutions for adding nesting to these formats are as follows:

level1.key1=value level1.key2=value level2.key1=value 

not a pretty look, a lot of redundancy and hard to move things between nodes.

JSON is not a bad language, but it is designed for simple analysis of computers (this is valid JavaScript), so it is not wildly used for configuration files.

JSON is as follows:

 {"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"} ] } }} 

In my opinion, it is too cluttered with commas and quotes.

YAML is suitable for configuration files, here is an example:

 invoice: 34843 date : 2001-01-23 bill-to: &id001 given : Chris family : Dumars 

however, I don’t really like its syntax, and I think that using spaces to define areas makes things a little fragile (think about inserting a block into a different level of nesting).

A few days ago, I started writing my own language for a configuration file, I named it Swush .

Here are a few examples: as simple key-value pairs:

 key:value key:value2 key1:value3 

or as more complex and commented

 server{ connector{ protocol : http // HTTP or BlahTP port : 8080 # server port host : localhost /* server host name*/ } log{ output{ file : /var/log/server.log format : %t%s } } } 

Swush supports strings in simple form above or in quotation marks, which allows you to use spaces and even new lines within strings. I am going to add arrays in the near future, for example:

 name [1 2 bc "Delta force"] 

There is a Java implementation, but more implementations are welcome. :). check the site for more information (I covered most of this, but the Java API provides some interesting features, such as a selector).

+9
Apr 27 '09 at 7:34
source share

This is an important issue.

Most alternatives (JSON, YAML, INI files) are easier to parse than XML.

Also, in languages ​​like Python, where everything is source, it's easier to just put your configuration in a clearly labeled Python module.

However, some people will say that XML has some advantage over JSON or Python.

What is most important in XML is that the “versatility” of the XML syntax is not really important when writing an application-specific configuration file. Since portability of the configuration file does not matter, some Python users write their configuration files in Python.




Edit

The security of the configuration file does not matter. "Python configuration in Python is a security risk," seems to ignore the fact that Python is already installed and running as the source. Why handle a complex hack in a configuration file when you have a source? Just crack the source.

I heard that people say that “someone” can hack your application through a configuration file. Who is this "someone"? System Administrator? Dba? The developer? There are not many mysterious "someone" with access to configuration files.

And anyone who could crack the Python configuration file for vile purposes could possibly install keyloggers, fake certificates or other more serious threats.

+37
Apr 26 '09 at 23:07
source share
  • XML is easy to parse. In most languages, several popular, lightweight, functional, and / or free XML parsing libraries are available.
  • XML is easy to read. This is a very readable markup language, so it’s easy for people to write as well as write on computers.
  • Well specified XML. Everyone and his dog know how to write decent XML, so there is no confusion about the syntax.
  • XML is popular. Somewhere along the way, some important people ™ began to push the idea that XML is the “future,” and many are buying it.
  • XML is a bidirectional format. This spaces, comments and order are saved. You can programmatically download, modify, and then save it while maintaining the formatting. This is important for tools that users can use to customize their applications. This is one of the reasons XML has soared (the world has become more technical, so this is less necessary).
  • XML has optional schema validation. Important for tools and complex configuration formats.
  • XML has namespaces. This allows you to embed other configurations or annotations without the effect of parsing. In other configuration formats, this is usually done as with special hack comments or property name changes.

As a side note, I'm not trying to protect XML. He uses it, and I will use it in the project when I get back to it. In many cases, and especially in configuration files, its only advantage is that it is a standardized format, and I think it is far outweighed by numerous shortcomings (i.e. Too verbose). However, my personal preferences do not matter - I just answered why some people can use XML as a configuration file format. I personally will never be.

+26
Apr 26 '09 at 23:01
source share

Because XML sounds cool and entrepreneurial.

Edit: I did not understand that my answer was so vague until the commentator asked for a definition of the enterprise. Quoting Wikipedia :

[...] the term "entrepreneurship" should go beyond the "excesses for small organizations", implying that the software is too complicated even for large organizations, and simpler, more proven solutions are available.

My point is that XML is a buzzword and, as such, is overused. Despite other opinions, XML is not easy to parse (just look at libxml2, its source package gzipped currently exceeds 3 MB). Due to the amount of redundancy, it is also unpleasant to write manually. For example, Wikipedia lists XML configuration as one of the reasons jabberd popular in favor of other implementations.

+24
Apr 26 '09 at 23:00
source share

XML is a well-developed and accepted standard that makes reading and understanding easier than proprietary configuration formats.

In addition, it is worthwhile to understand that XML serialization is a public tool available in most languages, which simplifies the storage of object data for developers. Why create your own way to maintain a hierarchy of complex data when someone else has done the job for you?

.NET: http://msdn.microsoft.com/en-us/library/system.xml.serialization.aspx

PHP: http://us.php.net/serialize

Python: http://docs.python.org/library/pickle.html

Java: http://java.sun.com/developer/technicalArticles/Programming/serialization/

+13
Apr 26 '09 at 22:57
source share

Another point, if you have an XSD file (schema file) to describe your configuration file, it is trivial for your application to check the configuration file.

+8
Apr 26 '09 at 23:00
source share

Since XML parsing is relatively simple, and if your schema is clearly specified, any utility can read and write information easily.

+3
Apr 26 '09 at 22:57
source share

Well .., XML is a general-purpose specification that can contain descriptions, embedded information, and data about something. And there are many APIs and software that can analyze and read it.

Thus, it is very easy to describe something in a formal way, these are well-known cross-platforms and applications.

+2
Apr 26 '09 at 23:02
source share

Here are a few historical reasons:

  • W3C Moves From Creating Tools In Perl To Java
  • The core of Apache has moved from creating tools in Perl to Java.
  • Java has a lot of XML APIs
  • Configuration can be done in Java
  • Configuration via XML and property files for non-Java developers.

JTidy configuration vs tidy configuration is a prime example of this.

+1
Apr 16 '14 at 2:07
source share

Because XML allows you to basically create your own semantic markup, which can be read by a parser created in almost any language. An added benefit is that a configuration file written in XML can be used in projects in which you use two or more languages. IF you had to create a configuration file where everything was defined as variables for a particular language, it will only work in that language, obviously.

0
Apr 26 '09 at 23:02
source share

The main advantage of XML and the reason why it is so popular is that it is popular in the java world, and therefore all corporate applications written in java use it, and also because web services and soap are based on xml and used a lot in enterprise applications.

And so far, JSON and all other formats are not well supported by the industry, with the exception of ajax applications. In addition, JSON does not have a schema language or a specific parsing api, like XML.

Even if, roughly speaking, JSON doesn't need tons of xml stuff, at least not like that, and I say web services when I say this ...

0
Apr 16 '12 at 20:32
source share

One of the reasons that were not mentioned in the other answers is the Unicode / text / name encoding. Do I need a Chinese line in the file? No problems. This may seem trivial, but when XML was introduced, it is not. Obviously not in INI files.

Another thing is the first thing that gave us the opportunity to have structured data with lists, dictionaries, or whatever you want, which is simultaneously processed by a machine and a person.

It has flaws, but what else could you use? Yaml looks great, but I'm afraid to present it in the projects I'm working on because I just see in my imagination all these problems with people who put a space in the wrong place or merge tools that don't care about them.

0
Apr 27 '16 at 9:23
source share



All Articles