Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Parsing XML Schema with Xerces-J

From: johnmmcparland <johnmmcparland@----------.--->
To: NULL
Date: 4/9/2009 1:39:00 AM
Hi all,

I have a Java application which stores customer details in an XML file
and I have an XML schema to match it.  The application provides a GUI
to effectively edit the XML.  So if I have XML like this;

<Customers>
   <Customer>
     <id>0</id>
     <name>John Smith</name>
     <contactDetails>
         <type>email</type>
         <value>jsmith@e...</value>
     </contactDetails>
     <comment>Blah</comment>
   </Customer>
</Customers>

and a schema

<xs:element name="Customers" type="CustomersType"/>

<xs:complexType name="CustomersType">
   <xs:sequence>
      <xs:element name="Customer" type="CustomerType" minOccurs="0"
maxOccurs="unbounded" />
   </xs:sequence>
</xs:complexType>

<xs:complexType name="CustomerType">
  <xs:sequence>
    <xs:element name="id" type="int" minOccurs="1" maxOccurs="1"/>
    <xs:element name="name" type="string" minOccurs="1" maxOccurs="1"/
>
    <xs:element name="contactDetails" type="contactDetailsType"
minOccurs="1" maxOccurs="2"/>
    <xs:element name="comment" type="string" minOccurs="0"
maxOccurs="1"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="contactDetailsType">
     <xs:sequence>
        <xs:element name="type" type="contactType" minOccurs="1"
maxOccurs="1"/>
        <xs:element name="value" type="string" minOccurs="1"
maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="contactType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="email"/>
        <xs:enumeration value="phone"/>
    </xs:restriction>
</xs:complexType>

I want to provide a GUI to edit that.  The trick is I don't want to
hard-code the names of the fields etc.  So if the GUI provides a form
to edit said customer then they would have a form that has;

id [ 0 ] *
name [ John Smith ] *
contact type [ email ]*
contact value [ johnsmith@e... ] *
comment [ Blah ]
* indicates required field

and I could easily add say a third contact type (postal address) and I
wouldn't have to write any code to do this.

This feels like a fairly generic and common exercise so I hope someone
else has done it.

Regards,

John


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent