Symfony2 - 为什么要使用XML进行设置/配置?

时间:2022-10-22 17:04:01

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

对于每种类型的文件,是否有兴趣使用XML over YAML:

  • config
  • 配置
  • security
  • 安全
  • routing
  • 路由
  • services
  • 服务
  • translations
  • 译文

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

我想全局询问XML vs YAML和JSON,但我会坚持这些主题:)

4 个解决方案

#1


13  

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

在我公司针对上述每一点的项目中,我们使用YAML,因为它更具可读性。最具可读性。最可读的。


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...

我可以想象在YAML上使用XML的唯一抽象情况 - 可能是某些动态文件编写者,因为使用SimpleXML或类似的东西更容易操作节点。例如,如果您需要定义一些配置文件,请在测试中构建模式等...

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.

由于我的回答被接受了,我不能不同意m2mdas - 正如他在下面的回答中提到的,使用XML的另一个有意义的是IDE的自动完成支持。

#2


10  

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.

xml congiruration的优点是IDE自动完成和即时验证。作为具体模式定义定义的元素,IDE可以立即验证元素,而这在YAML或JSON中是不可能的。另外我认为Symfony在处理之前根据定义验证配置中的xml元素。

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.

通过验证,我的意思是根据定义的模式验证元素结构。最好在处理之前验证配置。例如,具有数百个服务对象定义的services.yml在第99个服务定义中存在错误。 Yaml解析器将逐步解析,创建昂贵的cpu密集型服务对象,并在第99次定义时失败。对于具有已定义模式的service.xml,您可以验证元素结构并在可以的情况下处理它们。显然第二个过程是有效的。

#3


8  

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

Fabien Potencier在他的博客上写了关于在YAML上使用XML的优点:

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

    加载XML文件时,会使用内置的services.xsd文件自动验证它;

  • The XML can be auto-completed in IDEs;

    XML可以在IDE中自动完成;

  • The XML format is faster than the YAML one;

    XML格式比YAML格式快;

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

    XML格式没有外部依赖关系(YAML格式依赖于sfYAML组件)。

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

虽然这篇文章是为symfony1.x编写的,但这些点也绝对可以应用于Symfony2。

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

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

#4


2  

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

支持XML的另一个方面是使用PHP常量定义参数的可能性,这对于YAML是不可能的。

#1


13  

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

在我公司针对上述每一点的项目中,我们使用YAML,因为它更具可读性。最具可读性。最可读的。


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...

我可以想象在YAML上使用XML的唯一抽象情况 - 可能是某些动态文件编写者,因为使用SimpleXML或类似的东西更容易操作节点。例如,如果您需要定义一些配置文件,请在测试中构建模式等...

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.

由于我的回答被接受了,我不能不同意m2mdas - 正如他在下面的回答中提到的,使用XML的另一个有意义的是IDE的自动完成支持。

#2


10  

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.

xml congiruration的优点是IDE自动完成和即时验证。作为具体模式定义定义的元素,IDE可以立即验证元素,而这在YAML或JSON中是不可能的。另外我认为Symfony在处理之前根据定义验证配置中的xml元素。

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.

通过验证,我的意思是根据定义的模式验证元素结构。最好在处理之前验证配置。例如,具有数百个服务对象定义的services.yml在第99个服务定义中存在错误。 Yaml解析器将逐步解析,创建昂贵的cpu密集型服务对象,并在第99次定义时失败。对于具有已定义模式的service.xml,您可以验证元素结构并在可以的情况下处理它们。显然第二个过程是有效的。

#3


8  

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

Fabien Potencier在他的博客上写了关于在YAML上使用XML的优点:

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

    加载XML文件时,会使用内置的services.xsd文件自动验证它;

  • The XML can be auto-completed in IDEs;

    XML可以在IDE中自动完成;

  • The XML format is faster than the YAML one;

    XML格式比YAML格式快;

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

    XML格式没有外部依赖关系(YAML格式依赖于sfYAML组件)。

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

虽然这篇文章是为symfony1.x编写的,但这些点也绝对可以应用于Symfony2。

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

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

#4


2  

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

支持XML的另一个方面是使用PHP常量定义参数的可能性,这对于YAML是不可能的。