|
1 | 1 | xsd2xml
|
2 | 2 | =======
|
3 | 3 |
|
4 |
| -Java-based XSD to XML generator |
| 4 | +Java-based XML Schema (XSD) to XML instance generator |
| 5 | + |
| 6 | +# Introduction |
| 7 | + |
| 8 | +_xsd2xml_ is a Java-based XML Schema document to XML instance generator. Unlike the approach used by JAXB, |
| 9 | +there is no schema compilation step to generate any code. Instead, xsd2xml uses |
| 10 | +the [Apache XMLSchema](http://ws.apache.org/commons/XmlSchema/ "Apache XMLSchema") library to |
| 11 | +parse the given schema document and takes the root element for which the XML document must |
| 12 | +be generated. |
| 13 | + |
| 14 | +_xsd2xml_ originated as a component in the [Examine](http://www.stratumsoft.com/) Web Services Testing tool |
| 15 | +and is used to generate SOAP request message payloads using the XML Schema present in a WSDL 1.1 |
| 16 | +document |
| 17 | + |
| 18 | +## Features |
| 19 | + |
| 20 | +* Generate attributes marked optional |
| 21 | +* Generate elements with minOccurs = 0 |
| 22 | +* Generate the other branches in choice as comments |
| 23 | +* Generate comments when processing particles |
| 24 | +* Generate repeating elements based on minOccurs/maxOccurs value |
| 25 | +* Generate recursive elements upto a configurable depth |
| 26 | +* Generate default values for the different XmlSchema types |
| 27 | +* Generate compact XML or pretty-printed/formatted XML |
| 28 | + |
| 29 | +# Usage |
| 30 | + |
| 31 | +### Load the XML Schema file from which to generate XML instances |
| 32 | + |
| 33 | + String path = "..." |
| 34 | + InputStream is = this.getClass().getResourceAsStream(path); |
| 35 | + URL xsdUrl = this.getClass().getResource(path); |
| 36 | + |
| 37 | +### Create an XmlSchemaCollection and XmlSchema instance |
| 38 | + |
| 39 | + XmlSchemaCollection coll = new XmlSchemaCollection(); |
| 40 | + coll.setBaseUri(xsdUrl.toString()); |
| 41 | + |
| 42 | + StreamSource source = new StreamSource(is); |
| 43 | + XmlSchema schema = coll.read(source); |
| 44 | + |
| 45 | +### Configure the XML generation options |
| 46 | + |
| 47 | + XmlGenOptions options = new XmlGenOptions(); |
| 48 | + options.setGenCommentsForParticles(true); |
| 49 | + options.setGenChoiceOptionsAsComments(false); |
| 50 | + options.setMaxRecursiveDepth(1); |
| 51 | + options.setMaxRepeatingElements(2); |
| 52 | + options.setDefVals(DefaultValues.DEFAULT); |
| 53 | + |
| 54 | +### Create an instance of SchemaTypeXmlGenerator |
| 55 | + |
| 56 | + SchemaTypeXmlGenerator generator = new SchemaTypeXmlGenerator(coll, options); |
| 57 | + |
| 58 | +### Generate XML by specifying the root element QName |
| 59 | + |
| 60 | + boolean isPretty = true; |
| 61 | + String xml = generator.generateXml(elName, isPretty); |
| 62 | + |
| 63 | +# License |
| 64 | + |
| 65 | +*xsd2xml* is being distributed with dual-license: |
| 66 | + |
| 67 | +* [GPLv3](http://www.gnu.org/licenses/gpl-3.0.html "GPLv3") license for open-source usage |
| 68 | +* Commercial license for proprietary/closed-source/commercial products that require this dynamic XML generation |
| 69 | + functionality. Please visit [http://www.stratumsoft.com](http://www.stratumsoft.com) or contact Stratumsoft Support |
| 70 | + at <support@stratumsoft.com> for information about how to obtain a commercial license and its usage. |
0 commit comments