7

I doubt if there is something like this but I thought to ask though:
Does anyone know if there is a library in Java that reads an xsd file and "creates" the defined elements e.g. in a String format to use in the code?
E.g. read in the following schema:

<?xml version="1.0" encoding="utf-8"?>
        <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="Address">
            <xs:complexType>
              <xs:sequence>
                  <xs:element name="Street" type="xs:string" />
                  <xs:element name="Town" type="xs:string" />
                  <xs:element name="Country" type="xs:string" minOccurs="0" />
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:schema>

And have a String in the following format:

<Address>  
  <Street></Street>
  <Town></Town>
  <Country></Country>
</Address>

Automatic tools do something similar, i.e. parse a WSDL and from the types section create for example JAXB classes that can be instances of the elements defined in schema.
Is there any library to do this?

UPDATE:
For example in Eclipse when creating an xml descriptor for a web application it presents a tree table with all the required elements for the users to fill in according to schema. How do they do it? I imagine they parse the xsds included in the jars
Any input is very welcome.
Thank you!

4
  • Doesn't JAXB do something like this? Or am I misunderstanding the question? Commented Dec 19, 2010 at 19:09
  • @Hovercraft:I do not want to create any classes. I only want to read in an xsd file and create a string of the elements defined.I guess it is similar to how jaxb classes are created Commented Dec 19, 2010 at 19:13
  • 1
    I can't see why something like this would exist? What's the requirement? How many empty elements are generated for a 0-to-many element? Also, does it matter that the output does not capture the type? Commented Dec 19, 2010 at 19:13
  • @Synesso:Well the idea is that the empty element would be presented to the user through a UI and the user would fill in the required values Commented Dec 19, 2010 at 19:23

2 Answers 2

1

If its a WSDL file with which you want to generate Java classes, then Axis WSDL2Java (based on JAXB) can be used to get classes based on the schema defined in the WSDL.

JAXB also offers binding framework which you might want to look up.

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/twbs_jaxbschema2java.html

Above link should be useful.

Sign up to request clarification or add additional context in comments.

1 Comment

I do not want to generate classes. Yes I know these frameworks. I am interested only in creating elements from xsd.
1

oXygen has an XML instance generator that can generate a set of XML document samples based on a given XML Schema.

You can also invoke it from the commandline.

2 Comments

Can this be used at runtime?I am not interested in a tool that simply generates samples from xsd. I am interested in using it at runtime for any xsd provided by user
Yes, you can. Either exec the commandline scripts provided, or setting up the proper classpath references, etc. using the scripts as a guide (oXygen is a Java based tool). Then at runtime give it a URI to an XSD to gen files from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.