简体   繁体   English

从XSD生成Sample XML的任何Java“API”?

[英]Any Java “API” to generate Sample XML from XSD?

As part of our application we need to develop a module that takes in an XSD schema and gives out a sample XML. 作为我们应用程序的一部分,我们需要开发一个接收XSD架构并提供示例XML的模块。 The XSD schemas will be supplied during runtime. XSD架构将在运行时提供。 So is there any Java API out there that can do the job? 那么有没有可以完成这项工作的Java API?

Searched this forum and found the following similar questions. 搜索了这个论坛,发现了以下类似的问题。 But the discussions were around tools to generate sample XML from XSD. 但讨论围绕着从XSD生成示例XML的工具。 Could not find any reference to APIs. 找不到任何API参考。
how-to-generate-sample-xml-documents-from-their-dtd-or-xsd 如何对生成样本-XML的文档从-他们-DTD或- XSD
tool-to-generate-xml-file-from-xsd-for-testing 工具对生成的XML文件从- XSD的用于测试
xml-instance-generation-from-xml-schema-xsd XML实例代从- XML的架构XSD

我发现java API可以从XSD http://code.google.com/p/jlibs/wiki/XSInstance生成XML样本,

There is no such API, but it's possible. 没有这样的API,但它是可能的。 'gives out sample XML' means that you will have to implement generation of sample XML node(s) from XSD basic types like <xs:element name="value" type="xs:integer" minOccurs="0"/> , taking care of minoccurs/maxoccurs attributes, not storing dates in xs:integer nodes, etc, etc.. '给出样本XML'意味着你必须从XSD基本类型实现样本XML节点的生成,如<xs:element name="value" type="xs:integer" minOccurs="0"/> ,处理minoccurs / maxoccurs属性,不在xs:integer存储日期xs:integer节点等等。

Once it's done, the rest is not a problem: traversing XSD with XPath or org.w3c.dom.* , flattening complex types and extensions will do the trick. 一旦完成,剩下的就不是问题了:使用XPathorg.w3c.dom.*遍历XSD org.w3c.dom.* ,展平复杂类型和扩展将会起到作用。 I bet you'll receive working traversing code here on stackoverflow within minutes after posting question. 我打赌你会在发布问题后的几分钟内在stackoverflow上收到工作遍历代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM