任何从 XML 实例文档生成 XSD 模式的工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/74879/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:00:45  来源:igfitidea点击:

Any tools to generate an XSD schema from an XML instance document?

xmlxsdschemagenerator

提问by Matt Dillard

I am looking for a tool which will take an XML instance document and output a corresponding XSD schema.

我正在寻找一种工具,它将采用 XML 实例文档并输出相应的 XSD 模式。

I certainly recognize that the generated XSD schema will be limited when compared to creating a schema by hand (it probably won't handle optional or repeating elements, or data constraints), but it could at least serve as a quick starting point.

我当然认识到,与手动创建模式相比,生成的 XSD 模式会受到限制(它可能不会处理可选或重复元素或数据约束),但它至少可以作为一个快速起点。

采纳答案by Danimal

the Microsoft XSD inference toolis a good, free solution. Many XML editing tools, such as XmlSpy (mentioned by @Garth Gilmour) or OxygenXML Editor also have that feature. They're rather expensive, though. BizTalk Server also has an XSD inferring tool as well.

微软XSD推理工具是一个很好的,免费的解决方案。许多 XML 编辑工具,例如 XmlSpy(由 @Garth Gilmour 提到)或 OxygenXML Editor 也具有该功能。不过,它们相当昂贵。BizTalk Server 也有一个 XSD 推断工具。

edit: I just discovered the .net XmlSchemaInferenceclass, so if you're using .net you should consider that

编辑:我刚刚发现了 .net XmlSchemaInference类,所以如果你使用 .net 你应该考虑

回答by Dario

You can use an open source and cross-platform option: inst2xsd from Apache's XMLBeans. I find it very useful and easy.

您可以使用开源和跨平台选项:来自Apache 的 XMLBeans 的inst2xsd 。我觉得它非常有用和容易。

Just download, unzip and play (it requires Java).

只需下载、解压和播放(它需要 Java)。

回答by Derferman

Trangis the best option here. Open source and cross platform (although Java is required)

董里是这里的最佳选择。开源和跨平台(虽然需要Java)

From the Trang Website:

来自董里网站:

Trang converts between different schema languages for XML. It supports the following languages

  • RELAX NG (XML syntax)
  • RELAX NG compact syntax
  • XML 1.0 DTDs
  • W3C XML Schema

A schema written in any of the supported schema languages can be converted into any of the other supported schema languages, except that W3C XML Schema is supported for output only, not for input.

Trang can also infer a schema from one or more example XML documents.

Trang 在不同的 XML 模式语言之间进行转换。它支持以下语言

  • RELAX NG(XML 语法)
  • RELAX NG 紧凑语法
  • XML 1.0 DTD
  • W3C XML 架构

以任何受支持的模式语言编写的模式可以转换为任何其他受支持的模式语言,但 W3C XML 模式仅支持用于输出,不支持用于输入。

Trang 还可以从一个或多个示例 XML 文档推断模式。

Download Link

下载链接

回答by Nathan Donnellan

In VS2010 if you load an XML file into the editor, click the XML menu >> Create Schema.

在 VS2010 中,如果您将 XML 文件加载到编辑器中,请单击 XML 菜单 >> 创建架构。

回答by edorian

There also is XML schema learnerwhich is available on Github.

GithubXML schema learner上也有。

It can take multiple xml filesand extract a common XSD from all of those files.

它可以采用多个 xml 文件从所有这些文件中提取一个公共 XSD

回答by Pat Hermens

If you have .Net installed, a tool to generate XSD schemas and classes is already included by default.
For me, the XSD tool is installed under the following structure. This may differ depending on your installation directory.

如果您安装了 .Net,则默认情况下已包含生成 XSD 架构和类的工具。
对我来说,XSD 工具安装在以下结构下。这可能会因您的安装目录而异。

C:\Program Files\Microsoft Visual Studio 8\VC>xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.

xsd.exe -
   Utility to generate schema or class files from given source.

xsd.exe <schema>.xsd /classes|dataset [/e:] [/l:] [/n:] [/o:] [/s] [/uri:]
xsd.exe <assembly>.dll|.exe [/outputdir:] [/type: [...]]
xsd.exe <instance>.xml [/outputdir:]
xsd.exe <schema>.xdr [/outputdir:]

Normally the classes and schemas that this tool generates work rather well, especially if you're going to be consuming them in a .Net language

通常,这个工具生成的类和模式工作得很好,特别是如果你打算用 .Net 语言使用它们

I typically take the XML document that I'm after, push it through the XSD tool with the /o:<your path>flag to generate a schema (xsd) and then push the xsd file back through the tool using the /classes /L:VB (or CS) /o:<your path>flags to get classes that I can import and use in my day to day .Net projects

我通常使用我想要的 XML 文档,将它推/o:<your path>送到带有标志的 XSD 工具以生成模式 (xsd),然后使用/classes /L:VB (or CS) /o:<your path>标志将 xsd 文件推送回工具以获取我可以导入和使用的类在我日常的 .Net 项目中

回答by Robert Gould

If all you want is XSD, LiquidXML has a free version that does XSDs, and its got a GUI to it so you can tweak the XSD if you like. Anyways nowadays I write my own XSDs by hand, but its all thanks to this app.

如果您只需要 XSD,LiquidXML 有一个免费版本可以执行 XSD,并且它有一个 GUI,因此您可以根据需要调整 XSD。无论如何,现在我手工编写自己的 XSD,但这一切都归功于这个应用程序。

http://www.liquid-technologies.com/

http://www.liquid-technologies.com/

回答by Andreas Petersson

if you are working in the java world - intelliJ ideahas also extensive xml support, including xsd generation and samle xml from xsd generation, and with plugins you can get xslt debuggers. - especially nice if you plan to use tools such as jaxb afterwards.

如果您在 Java 世界中工作 - intelliJ idea也有广泛的 xml 支持,包括 xsd 生成和 xsd 生成的 samle xml,并且使用插件您可以获得 xslt 调试器。- 如果您打算之后使用诸如 jaxb 之类的工具,则特别好。

回答by Garth Gilmour

Altova XmlSpy does this well - you can find an overview here

Altova XmlSpy 做得很好 - 您可以在此处找到概述

回答by v_e

This is an old thread but I thought it could be useful to post this link: just found this tool: xsd-gen Generate XML Schema from XML

这是一个旧线程,但我认为发布此链接可能很有用:刚刚找到了这个工具: xsd-gen Generate XML Schema from XML

and it just did what I needed.

它只是做了我需要的。