1

Is there a way to convert a XML schema to a tree of Java objects with considering of type, ref etc.? I mean, take this

<xs:element name="root">
  <xs:complexType>
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="elem" type="type1">
    </xs:all>
  </xs:complexType>
</xs:element>

<xs:complexType name="type1">
  <xs:sequence>
    <xs:element name="A" type="xs:string"/>
    <xs:element name="B" type="xs:string"/>
    <xs:element name="C" type="xs:string"/>
    <xs:any minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

and make a tree: root element "root" with child "elem" (with marked min and maxOccurs). "elem" also has children "A", "B", "C" and "any".

Is there such a way? Some library maybe? And if not, what should I consider, aside from type and ref, to write such linearization thing myself?

  • 1
    Possible duplicate of [Generate Java classes from .XSD files...?](http://stackoverflow.com/questions/686453/generate-java-classes-from-xsd-files) – maraca Nov 11 '15 at 18:41
  • 1
    [**JAXB**](https://jaxb.java.net/tutorial/) – kjhughes Nov 11 '15 at 19:11

1 Answers1

0

Yes, it's possible. This implementation is very well engineered - I have used it myself: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.emf.doc%2Ftutorials%2Fxlibmod%2Fxlibmod.html

It is based on Eclipse Modelling Framework, but you don't have to install all of Eclipse in order to use it.

kimbert
  • 2,376
  • 1
  • 10
  • 20