Parsing XML Schema with Xerces-J



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;

<name>John Smith</name>
<value>[email protected]</value>

and a schema

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

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

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

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

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

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 [ (e-mail address removed) ] *
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.




Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question