Parsing XML Schema with Xerces-J


J

johnmmcparland

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>[email protected]</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="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 [ (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.

Regards,

John
 
Ad

Advertisements


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

Top