Java Methods for Polling XSD Files

I have a set of xsd files for different data types. In the Java world, the best way to create a list of type properties?

eg. with these two files.

file: customer.xsd

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="customer">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="number" type="xs:integer"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="address" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

file: order.xsd

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="customer">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderid" type="xs:integer"/>
      <xs:element name="customer" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

I would like to do two things

1. Java application that reads in XSD and then processes (somehow?). Therefore, when you run the program, it can print properties

> java -jar printtypes.jar -f customer.xsd
> number : Integer
> name : String
> address : String

2. some kind of conversion that generates a new file

file: customer.properties

<propertylist>
<prop>
 <name> orderid </name>
 <type> integer </type>
</prop>
<prop>
 <name> customer </name>
 <type> string</type>
</prop>
</propertylist>

(1) , java- Java-, JAXB. , , . - . ArrayList, , .

++-, Java. Google - JAVA/XSD, , , , .

+5
3
+2

1. XPath. , :

/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element/@name

:

  • number
  • name
  • address

: - ?

2. XSLT . :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/xs:schema/xs:element/xs:complexType/xs:sequence">
<propertylist>
    <xsl:for-each select="xs:element">
    <prop>
        <name><xsl:value-of select="@name"/></name>
        <type><xsl:value-of select="@type"/></type>
    </prop>
    </xsl:for-each>
</propertylist>
</xsl:template>
</xsl:stylesheet>

customer.xsd :

<propertylist xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <prop>
        <name>number</name>
        <type>xs:integer</type>
    </prop>
    <prop>
        <name>name</name>
        <type>xs:string</type>
    </prop>
    <prop>
        <name>address</name>
        <type>xs:string</type>
    </prop>
</propertylist>

, Java .

+2

XSOM, , .

Saxon SCM. Saxon XML, SCM. , XSD. , XSOM , Java, Saxon SCM , XSLT XQuery.

+1

All Articles