0

I have a big schema file (.xsd) that has choices that you can choose from:

<xs:element name="MyData">
    <xs:complexType>
        <xs:choice maxOccurs="unbounded">
            <xs:element name="AAA" type="AAAType" maxOccurs="unbounded" />
            <xs:element name="BBB" type="BBBType" maxOccurs="unbounded" />
            <xs:element name="CCC" type="CCCType" maxOccurs="unbounded" />
            <xs:element name="DDD" type="DDDType" maxOccurs="unbounded" />
            <xs:element name="EEE" type="EEEType" maxOccurs="unbounded" />
            <xs:element name="FFF" type="FFFType" maxOccurs="unbounded" />
            <xs:element name="GGG" type="GGGType" maxOccurs="unbounded" />
            <xs:element name="HHH" type="HHHType" maxOccurs="unbounded" />
            <xs:element name="III" type="IIIType" maxOccurs="unbounded" />
            <xs:element name="JJJ" type="JJJType" maxOccurs="unbounded" />
            <xs:element name="KKK" type="KKKType" maxOccurs="unbounded" />
            <xs:element name="LLL" type="LLLType" maxOccurs="unbounded" />
            <xs:element name="MMM" type="MMMType" maxOccurs="unbounded" />
            <xs:element name="NNN" type="NNNType" maxOccurs="unbounded" />
            <xs:element name="OOO" type="OOOType" maxOccurs="unbounded" />
            <xs:element name="PPP" type="PPPType" maxOccurs="unbounded" />
            <xs:element name="QQQ" type="QQQType" maxOccurs="unbounded" />
            <xs:element name="RRR" type="RRRType" maxOccurs="unbounded" />
            <xs:element name="SSS" type="SSSType" maxOccurs="unbounded" />
            <xs:element name="TTT" type="TTTType" maxOccurs="unbounded" />
            <xs:element name="UUU" type="UUUType" maxOccurs="unbounded" />
            <xs:element name="VVV" type="VVVType" maxOccurs="unbounded" />
            <xs:element name="WWW" type="WWWType" maxOccurs="unbounded" />
            <xs:element name="XXX" type="XXXType" maxOccurs="unbounded" />
            <xs:element name="YYY" type="YYYType" maxOccurs="unbounded" />
            <xs:element name="ZZZ" type="ZZZType" maxOccurs="unbounded" />
        </xs:choice>
        <xs:attribute name="version" type="xs:string" />
    </xs:complexType>
</xs:element>

Each type has its own sequences and complex types. Is there a way I can program something in Java where I give it the choice as a String, the program looks in the schema file and outputs a XML String? Similar to how you can create a XML file in Eclipse given the schema, I want to do it programmatically.

2
  • IntelliJ does this easily: Right click on the xsd and ask the IDE to create an XML for you. Commented Jun 17, 2016 at 13:36
  • Thanks for the reply; however, I want to do this with code. Commented Jun 17, 2016 at 14:04

1 Answer 1

2

Have a look at JAXB, which reads schema files and generates Java classes that follow the rules set in your XSD. It basically creates POJO objects, which have a bunch of setters to easily populate the required XML data.

JAXB is commonly used, and worthwhile learning anyway.

See the official documentation here

Lesson: Introduction to JAXB

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

3 Comments

Would you know how to do this with ADB? Just found out company wants to use that. I looked in the documentation but it's not that good.
I have only come across ADB in axis2, which is used for SOAP request. Here a link that may help Axis2 Databinding Framework
Yea, I saw that too. Not that extensive, unfortunately.

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.