简体   繁体   中英

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. The XSD schemas will be supplied during runtime. So is there any Java API out there that can do the job?

Searched this forum and found the following similar questions. But the discussions were around tools to generate sample XML from XSD. Could not find any reference to APIs.
how-to-generate-sample-xml-documents-from-their-dtd-or-xsd
tool-to-generate-xml-file-from-xsd-for-testing
xml-instance-generation-from-xml-schema-xsd

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

There is no such API, but it's possible. '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..

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. I bet you'll receive working traversing code here on stackoverflow within minutes after posting question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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