Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - Why use XML for settings/config?

Is there any interest to use XML over YAML for each of these types of file:

  • config
  • security
  • routing
  • services
  • translations

I would like to ask XML vs YAML and JSON globally, but I'll stick to these topics :)

like image 420
Pierre de LESPINAY Avatar asked Jul 31 '12 14:07

Pierre de LESPINAY


4 Answers

In my company projects for each of mentioned above points we use YAML because it is more readable. The most readable. The readablest.


EDIT:

The only abstract situation I can imagine for using XML over YAML - is probably for some dynamic file writers, since it is easier to manipulate with nodes using SimpleXML or something like that. For example, if you need to define some configuration file, build schemas in tests etc...

But it is hard to imagine another situation.


ANOTHER EDIT:

Since my answer was accepted, I cannot disagree with m2mdas - as he mentioned in his answer below, another thing that makes sense for using XML is IDE's autocompletion support.

like image 131
Vitalii Zurian Avatar answered Nov 15 '22 23:11

Vitalii Zurian


Advantage of xml congiruration is IDE auto-complete and instant validation. As elements defined by concrete schema definition, IDEs can instantly validate elements against it which is not possible in YAML or JSON. Also I think Symfony validates the xml elements in configuration against the definition before processing it.

Edit:

By validation I meant validate the element structure against the defined schema. It is better to validate the configuration before processing it. For example a services.yml with hundreds service object definition have an error in 99th service definition. Yaml parser will parse incrementally, create expensive cpu intensive service objects and will fail at 99th definition. Whereas for service.xml with defined schema you can validate the element structure and process them if it is OK. Obviously second process is efficient.

like image 25
Mun Mun Das Avatar answered Nov 15 '22 22:11

Mun Mun Das


Fabien Potencier wrote about the advantages of using XML over YAML on his blog:

  • When a XML file is loaded, it is automatically validated with the built-in services.xsd file;

  • The XML can be auto-completed in IDEs;

  • The XML format is faster than the YAML one;

  • The XML format as no external dependencies (the YAML format relies on the sfYAML component).

Although this post was written for symfony1.x, the points also can definitely be applied for Symfony2.

http://fabien.potencier.org/article/15/symfony-service-container-using-xml-or-yaml-to-describe-services

like image 22
seferov Avatar answered Nov 15 '22 22:11

seferov


Another thing in favor of XML is the possibility to define parameters using a PHP constant, which is not possible with YAML.

like image 36
Byscripts Avatar answered Nov 15 '22 23:11

Byscripts