C++ 从 xsd 生成 xml 文件的工具(用于测试)

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

tool to generate xml file from xsd (for testing)

c++xmlxsd

提问by Tim

I have an xsd file and have not done much xml manipulation, parsing, etc. I want/need test xml files for my code but don't have any samples. (I am using xerces to parse)

我有一个 xsd 文件,并没有做太多的 xml 操作、解析等。我想要/需要我的代码的测试 xml 文件,但没有任何示例。(我使用 xerces 来解析)

This is similar to: xml-instance-generation-from-xml-schema-xsd

这类似于:xml-instance-generation-from-xml-schema-xsd

but I don't really want to make it a two step process. (python or java)

但我真的不想让它成为一个两步过程。(蟒蛇或Java)

I just want to feed xsd file to some tool and have it generate a sample xml file. How can I do that?

我只想将 xsd 文件提供给某个工具并让它生成一个示例 xml 文件。我怎样才能做到这一点?

Also see: how-to-generate-sample-xml-documents-from-their-dtd-or-xsd

另请参阅:how-to-generate-sample-xml-documents-from-their-dtd-or-xsd

回答by Dan Breslau

Eclipse has tools for doing this (and it's free.)

Eclipse 有用于执行此操作的工具(而且它是免费的。)

EDIT(yeah, I was a little too terse) : What you want are the XSD editing tools in Eclipse. I know it's bundled with Eclipse IDE for Java EE Developers, and I think also with the Eclipse Modeling Toolsdownload. (It's also possible to add them into an existing Eclipse install, though I don't know exactly which plugin(s) you'll want to add.)

编辑(是的,我有点太简洁了):您想要的是 Eclipse 中的 XSD 编辑工具。我知道它与Eclipse IDE for Java EE Developers捆绑在一起,我认为也与Eclipse Modeling Tools下载捆绑在一起。(也可以将它们添加到现有的 Eclipse 安装中,但我不知道您要添加哪些插件。)

(I'd like to be more precise than that, but the eclipse.org web site models itself after Massachusetts roads: If you don't know where you are, you don't belong there.)

(我想更准确地说,但是 eclipse.org 网站以马萨诸塞州的道路为模型进行建模:如果您不知道自己在哪里,那么您就不属于那里。)

Anyway: Once you've got the right version of Eclipse, open the existing schema file for editing (or create a new one: select File -> New... Other ... XML / XML Schema ). When you're ready to generate a test XML file, locate the file in the Package Explorer (the navigator view, usually on the left side), right click on it, and select Generate/XML File.

无论如何:一旦您获得了正确版本的 Eclipse,打开现有的模式文件进行编辑(或创建一个新的:选择 File -> New... Other ... XML / XML Schema )。当您准备好生成测试 XML 文件时,在 Package Explorer(导航器视图,通常在左侧)中找到该文件,右键单击它,然后选择 Generate/XML File。

(What was I saying about navigability... ?)

(我在说什么关于适航性......?)

回答by Cheeso

Microsoft has published a "document generator" tool as a sample. This is an articlethat describes the architecture and operation of the sample app in some detail.

Microsoft 发布了一个“文档生成器”工具作为示例。 这篇文章比较详细地描述了示例应用程序的架构和操作。

If you just want to usethe doc generation tool, click hereand install the MSI.

如果您只想使用文档生成工具,请单击此处并安装 MSI。

It's free. The source is available. Requires the .NET Framework to run. Works only with XSDs. (not Relax NG or DTD).

免费。来源是可用的。需要 .NET Framework 才能运行。仅适用于 XSD。(不是放松 NG 或 DTD)。

回答by satyajit

I can do this very simply in VS2010, I don't know if this has been a new feature but this works pretty easy. Right click on the root element of an xsd in the 'xml schema explorer'. You will see an option to 'Generate Sample XML'. On clicking it VS creates a temp file

我可以在 VS2010 中非常简单地做到这一点,我不知道这是否是一个新功能,但这很容易。在“xml 模式资源管理器”中右键单击 xsd 的根元素。您将看到“生成示例 XML”的选项。单击它 VS 会创建一个临时文件

回答by Lyle

Oxygen'sXML Schema Editor can generate sample XML instance documents from a given Schema.

Oxygen 的XML 架构编辑器可以从给定的架构生成示例 XML 实例文档。

回答by Colin

Liquid XML will do XML sample generation, don't think there's a command line option but you can do it through the UI. Seems to do a pretty good job, gets all the data types/enums right, the only thing it seems to struggle on is patterns, but then understanding a regular expression well enough to produce a valid string is a bit tricky...

Liquid XML 会生成 XML 样本,不要认为有命令行选项,但您可以通过 UI 来完成。似乎做得很好,正确处理了所有数据类型/枚举,似乎唯一困难的是模式,但是很好地理解正则表达式以生成有效字符串有点棘手......

回答by hari gorak

Using Eclipse Ganymede or later you can generate xml from xsd. Just right click the xsd and navigate to generate > xml.

使用 Eclipse Ganymede 或更高版本,您可以从 xsd 生成 xml。只需右键单击 xsd 并导航到生成 > xml。

回答by Kyle W. Cartmell

I've used XMLSpyfor this in the past with great success.

我过去曾为此使用XMLSpy并取得了巨大成功。

回答by XMLStick

You may use XMLFoxfor this simple task.

您可以使用XMLFox来完成这个简单的任务。

回答by ljs

Have you taken a look at Microsoft's XML Schema Definition Tool (xsd.exe)?

你看过微软的XML 架构定义工具 (xsd.exe)吗?