title: Java methods for interrogating XSD files
body: <p>I have a set of xsd files for different data types. In the Java world, what is the best way to generate a list of the properties of the types?</p>
  
  <p>e.g. with these two files.</p>
  
  <p><strong>file: customer.xsd</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xs:element name="customer"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="number" type="xs:integer"/&gt;
        &lt;xs:element name="name" type="xs:string"/&gt;
        &lt;xs:element name="address" type="xs:string"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p><strong>file: order.xsd</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xs:element name="customer"&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="orderid" type="xs:integer"/&gt;
        &lt;xs:element name="customer" type="xs:string"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I'd like to do two things</p>
  
  <p><strong><em>1.</em></strong> a Java application which reads in the XSD and processes then (somehow?). So when you run the program it can print the properties out</p>
  
  <pre><code>&gt; java -jar printtypes.jar -f customer.xsd
  &gt; number : Integer
  &gt; name : String
  &gt; address : String
  </code></pre>
  
  <p><strong><em>2.</em></strong> some kind of transformation which generates a new file</p>
  
  <p>file: customer.properties</p>
  
  <pre><code>&lt;propertylist&gt;
  &lt;prop&gt;
   &lt;name&gt; orderid &lt;/name&gt;
   &lt;type&gt; integer &lt;/type&gt;
  &lt;/prop&gt;
  &lt;prop&gt;
   &lt;name&gt; customer &lt;/name&gt;
   &lt;type&gt; string&lt;/type&gt;
  &lt;/prop&gt;
  &lt;/propertylist&gt;
  </code></pre>
  
  <p>I tried to implement the program in (1) above using java reflection to interrogate Java classes generated by JAXB.
  This created an instance of the class and interrogated the values and fields, but it does not work where values are composed of a sequence that is empty. There is no way to get back to the original type of the value due to type erasure. You end up with an empty ArrayList of something, but you don't know what.</p>
  
  <p>I'm from the C++ work so I'm a bit lost with all this Java technology at the moment. My Google powers have failed me - most of the JAVA/XSD posts I've seen talk about validation which is not what I want to do.</p>