Convert XSD to a tree structure using Java

I want to create documentation for XML schemas.

My goal is to parse the xsd file and display it as a tree structure (when resolving all complex / anonymous types). In addition, I need to annotate all the elements in this tree with their power (as defined by the diagram).

The following small example may help clarify my problem.

a) xsd file:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="client" type="clientType" />
    <xs:complexType name="clientType">
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="first_name"/>
            <xs:element name="last_name"/>
            <xs:element name="address" type="addressType" 
                        minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="addressType">
        <xs:sequence>
            <xs:element name="street"/>
            <xs:element name="number" minOccurs="0" maxOccurs="1"/>
            <xs:element name="city"/>
            <xs:element name="zipcode"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

b) The result that I would like to see:

client [1]
  first_name [1]
  last_name [1]
  address [1..n]
    street [1]
    number [0..1]
    city [1]
    zipcode [1]

Does anyone know a Java based solution for this problem? Preferably based on Eclipse Schema Infoset , but I'm glad to use other libraries as well.

+5
source share
3 answers

XSOM XSD , .

+1

, XSD- XML, XML, , .

XSLT , , , minOccurs maxOccurs, .

, , .

0

Although I do not have the right solution, I would suggest the following: use a tool that is able to generate a sample XML instance based on XSD, for example. eclipse IDE (since it is open source, you need to extract the appropriate code and use it in a standalone solution). This XML should be very close to the required tree structure. Then parse the XSD and annotate the elements in the generated XML structure with powers.

0
source

All Articles