如何从 XML 文件示例中导出 DTD(或其他 XML 规范格式)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1815216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to derive DTD (or other XML spec format) from XML file samples
提问by lexu
Do you know of a tool that will derive a DTD (or other XML structure specification format) from a sample set of XML files?
您知道有一种工具可以从一组 XML 文件示例中派生出 DTD(或其他 XML 结构规范格式)吗?
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.
目前我们对 xml 编码的 DSL 唯一的(自动)验证是用 Perl 编写的遗留解析器,但出于一致性原因,所有 perl 代码必须移植到 C-sharp。
采纳答案by djc
http://www.stylusstudio.com/dtd_generator.htmlis actual software implementing a DTD generator.
http://www.stylusstudio.com/dtd_generator.html是实现 DTD 生成器的实际软件。
http://www.pmg.csail.mit.edu/~chmoh/pubs/wecwis.pdfseems 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.
http://www.pmg.csail.mit.edu/~chmoh/pubs/wecwis.pdf似乎是一篇关于你需要的东西的好论文,但我在任何地方都找不到(链接到)实际代码到目前为止,在论文中。
Here's another paper on this, again, no code to be found: http://www.softnet.tuc.gr/~minos/Papers/debull03.pdf.
这是另一篇关于此的论文,同样,找不到代码: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.)
最后,我还建议您考虑使用 RELAX NG 或 Schematron 来验证您的 XML。这些语言的表现力要强得多,使它们更易于阅读,并且在您可以验证的事物种类中更强大。(一定要跳过 XML Schema,它被广泛认为是一团糟。)
回答by Vinz
You can use xsd.exe(part of visual studio) to generate an XML schema for a given XML file.
您可以使用xsd.exe(visual studio 的一部分)为给定的 XML 文件生成 XML 架构。
回答by Moss
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
您可以使用以下链接在线生成架构,只需提供 xml 数据。 http://www.xmlforasp.net/codebank/system_xml_schema/buildschema/buildxmlschema.aspx
回答by flipper
You can download JetBrains IDEA community edition which is free. It has built-in tools for generating GTDs and Schemas:
您可以免费下载 JetBrains IDEA 社区版。它具有用于生成 GTD 和模式的内置工具:
http://www.jetbrains.com/idea/webhelp/generating-dtd.html
http://www.jetbrains.com/idea/webhelp/generating-dtd.html
Maybe not perfect but it is something.
也许不完美,但它是一些东西。
回答by Forethinker
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.
这是对我有用的程序DTDGenerator。你需要用Java编译它,但它运行良好。对于一种已经存在了很长时间的语言缺乏免费软件,我感到很惊讶,但在 Mozilla 公共许可证版本 1.0 下,该语言是免费的。
回答by user2657714
Just used http://www.freeformatter.com/xsd-generator.htmlto generate an xsd from an xml file. It also has a lot of other formatting possibilities!
刚刚使用http://www.freeformatter.com/xsd-generator.html从 xml 文件生成 xsd。它还有很多其他格式的可能性!
回答by Stephen Harmon
Altova's XMLSpyhas a DTD/XML Schema generator.
Altova 的 XMLSpy有一个 DTD/XML 模式生成器。
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.
生成的 DTD/XML Schema 通常需要稍作调整。例如,当您“打算”允许任何值时,该工具可能会枚举属性或元素的列表。你只是给它一个你的问题空间的样本,但是它必须从特定到一般。出于这个原因,当它无法读取我的想法时,我不会太弯曲变形。
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.
我认为生成的 dtd 或模式是一个起点。这比从零开始用手滚动要好。呃,如果你是从现有的 XML 文档开始,那就是。
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.
即使您不打算使用生成的 dtd,这也是了解一组不熟悉的 XML 文档结构的好方法。
回答by bill seacham
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.
XMLMax 编辑器将从 XML 文件创建 XSD。免费试用版(无注册/小下载文件)将为您完成此操作。如果您想在代码中执行此操作,.NET 框架有一个 XmlSchemaInference 类,该类可自动从 xml 文件创建 XSD。
回答by Johnny Baloney
You may want to try Trangor Instance to Schema Tool(part of XMLBeans).
您可能想尝试Trang或Instance to Schema Tool(XMLBeans 的一部分)。
I put them into a test with 1GB XML file. Here are the results:
我用 1GB XML 文件将它们放入测试中。结果如下:
max memory [kB] - 98,480
time [MM:SS] - 0:24
max memory [kB] - 5,993,240
time [MM:SS] - 7:36

