如何从 XML 文件示例派生 DTD(或其他 XML 规范格式)
您是否知道有一种工具可以从 XML 文件样本集导出 DTD(或其他 XML 结构规范格式)?
目前,我们对 xml 编码 DSL 的唯一(自动)验证是用 Perl 编写的遗留解析器,但出于一致性原因,所有 Perl 代码都必须移植到 C-sharp。
Do you know of a tool that will derive a DTD (or other XML structure specification format) from a sample set of XML files?
Currently the only (automatic) validation we have for an xml encoded DSL is a legacy parser written in Perl, but for consistency reasons all perl code must be ported to C-sharp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以使用 xsd.exe(Visual Studio 的一部分)为给定的 XML 文件生成 XML 架构。
You can use
xsd.exe
(part of visual studio) to generate an XML schema for a given XML file.http://www.stylusstudio.com/dtd_generator.html 是实现 DTD 生成器的实际软件。
http://www.pmg.csail.mit.edu/~chmoh /pubs/wecwis.pdf 似乎是一篇关于您需要的东西的好论文,但到目前为止我在论文中的任何地方都找不到(链接到)实际代码。
这是关于此的另一篇论文,同样,找不到代码: http:// www.softnet.tuc.gr/~minos/Papers/debull03.pdf。
最后,我还建议您考虑使用 RELAX NG 或 Schematron 来验证您的 XML。这些语言更具表现力,使它们更易于阅读,并且在您可以验证的事物方面更强大。 (一定要跳过 XML 模式,人们普遍认为它是一团糟。)
http://www.stylusstudio.com/dtd_generator.html is actual software implementing a DTD generator.
http://www.pmg.csail.mit.edu/~chmoh/pubs/wecwis.pdf seems like a nice paper on the kind of thing you'd need, but I can't find (links to) actual code anywhere in the paper so far.
Here's another paper on this, again, no code to be found: http://www.softnet.tuc.gr/~minos/Papers/debull03.pdf.
Finally, I'd also suggest you look into using RELAX NG or Schematron to validate your XML instead. Those languages are much more expressive, making them easier to read and more powerful in the kinds of things you can validate. (Be sure to skip XML Schema, which is widely considered to be a mess.)
您可以使用以下链接通过仅提供 xml 数据来在线生成架构。
http://www.xmlforasp.net/codebank/system_xml_schema/buildschema/buildxmlschema.aspx
You can use the following link for generating schema online, by providing just the xml data.
http://www.xmlforasp.net/codebank/system_xml_schema/buildschema/buildxmlschema.aspx
您可以免费下载 JetBrains IDEA 社区版。它具有用于生成 GTD 和架构的内置工具:
http://www.jetbrains .com/idea/webhelp/generating-dtd.html
也许并不完美,但它是一些东西。
You can download JetBrains IDEA community edition which is free. It has built-in tools for generating GTDs and Schemas:
http://www.jetbrains.com/idea/webhelp/generating-dtd.html
Maybe not perfect but it is something.
这是对我有用的程序 DTDGenerator。你需要用Java来编译它,但它运行得很好。我对这种已经存在很长时间的语言缺乏免费软件感到惊讶,但这个软件在 Mozilla 公共许可证版本 1.0 下是免费的。
Here is the program that worked for me DTDGenerator. You need to compile it with Java, but it works well. I am surprised by the lack of free software for a language that has been around for a long time, but this one is free under Mozilla Public License Version 1.0.
Altova 的 XMLSpy 有一个 DTD/XML 模式生成器。
生成的 DTD/XML 模式通常需要进行一些调整。例如,当您“打算”它允许任何值时,该工具可能会枚举属性或元素的列表。你只是给它一个问题空间的样本,但它必须从具体到一般。因此,当它无法读懂我的想法时,我不会变得太扭曲。
我认为生成的 dtd 或模式是一个起点。这比从零开始用手滚动要好。呃,如果您从现有的 XML 文档开始,那就是这样。
即使您不打算使用生成的 dtd,这也是让您了解一组不熟悉的 XML 文档的结构的好方法。
Altova's XMLSpy has a DTD/XML Schema generator.
The generated DTD/XML Schema usually requires a little tweaking. For example, the tool may enumerate a list of attributes or elements, when you "meant" for it to allow any value. You're only giving it a sample of your problem space, and it has to go from specific to general, though. For that reason, I don't get too bent out of shape when it fails to read my mind.
I consider the generated dtd or schema a starting point. It's better than rolling it by hand from zero. Er, if you're starting with existing XML documents, that is.
Even if you're not going to use the generated dtd, it's a pretty good way to get your head around the structure of a set of unfamiliar XML documents.
XMLMax 编辑器将从 XML 文件创建 XSD。免费试用版(无需注册/小下载文件)将为您做到这一点。如果您想在代码中执行此操作,.NET 框架有一个 XmlSchemaInference 类,可以自动从 xml 文件创建 XSD。
XMLMax editor will create an XSD from an XML file. The free trial(no registraton/small download file) will do this for you. If you want to do this in code, .NET framework has an XmlSchemaInference class that automatically creates an XSD from an xml file.
刚刚使用 http://www.freeformatter.com/xsd-generator.html 生成来自 xml 文件的 xsd。
它还具有许多其他格式的可能性!
Just used http://www.freeformatter.com/xsd-generator.html to generate an xsd from an xml file.
It also has a lot of other formatting possibilities!
您可能想尝试
Trang
或架构工具实例
( XMLBeans)。我用 1GB XML 文件对它们进行了测试。以下是结果:
Trang
:架构工具实例
:You may want to try
Trang
orInstance to Schema Tool
(part of XMLBeans).I put them into a test with 1GB XML file. Here are the results:
Trang
:Instance to Schema Tool
: