使用 XML 模式的优点和缺点是什么? [英] What are the advantages and disadvantages of using XML schemas?

查看:41
本文介绍了使用 XML 模式的优点和缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将 Microsoft SQL Server 2005 中的 XML 数据类型用于一个项目.团队中的一些成员和我觉得我们也应该使用 XSD,而另一个阵营的成员则认为我们应该保持 XML 的临时性,而不是将它们视为类型".

We are utilizing the XML data type in Microsoft SQL Server 2005 for a project. Some members of the team and I feel that we should also use XSDs while members of the other camp feel that we should keep the XMLs ad hoc and not treat them as "types".

XML 旨在为许多文本配置文件带来结构和中心性,这些文件是维护的噩梦.

The XMLs are an effort to bring structure and centrality to a number of text configuration files that are a maintenance nightmare.

我们使用 .NET 3.5/C# 并且我们的表是用适当的数据类型设计的.我的论点是,我们在思考为什么要打破这种方法时已经是面向类型的",因为它是 XML.原来的问题是因为文本文件缺少类型.不使用类型"方法会让我们面临同样的问题.

We are using .NET 3.5/C# and our tables are designed with the appropriate data types. My argument is that we are already "types oriented" in our thinking why break that approach because it is XML. It is because of the lack of types with the text files that the original problem occured. Not using a "types" approach leaves us open to the same problem.

可能是我对 XML 模式的好处的理解不正确.那么使用 XML 模式有哪些优点和缺点?

May be my understanding of the benefits of XML schemas are incorrect. So what are the advantages and disadvantages of using XML schemas?

推荐答案

不幸的是,即使是 XSD (W3C) 的创作机构也明白 XSD 是一种非常糟糕的技术.也就是说,它的意图不一定是坏的.C# 的主要优点之一是它是静态类型的.静态键入您的 XML 文档为它们提供了相同的好处.这里最好的方法是对您的类进行逆向工程,以使用 XML 序列化属性生成 Schema.当您执行此操作时,C# 将为您的 XML 文件创建一个自定义数据读取器,这将显着提高性能.

Unfortunately even the authoring body of XSD (W3C) understands that XSD is a pretty bad technology. That said, it's intention isn't necessarily bad. One of C#'s major benefits is that it is statically typed. Statically typing your XML documents gives them the same benefits. What's probably best here is reverse engineering your classes to produce the Schema using the XML serialization attributes. When you do this C# will create a custom data reader for your XML file which will dramatically improve performance.

XML 的最大成本之一是它必须进行字符串解析.您可以对 XML 文件(例如它们的结构)做出的假设越多,您的性能就可能越好.

One of the biggest costs of XML is that it has to be string parsed. The more assumptions you can make about your XML files (e.g. their structure), the better your performance is likely to be.

因此,最终就像许多事情一样,它们是否足以满足性能优势的需求,以证明开发人员的时间成本是合理的.或者是否有足够强烈的愿望使用静态类型系统来证明编写 XSD 的成本是合理的.

So ultimately like many things, is their enough of a need for performance benefits to justify the costs in developer time. Or is there a strong enough desire to use statically typed systems to justify the cost of writing the XSD.

最终,您的项目需求将决定您应该做什么,但静态类型和性能是需要考虑的主要好处.

Ultimately your project needs will dictate what you should do, but static-typing and performance are major benefits to consider.

这篇关于使用 XML 模式的优点和缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆