Parsing XML Schema with Xerces-J

Discussion in 'XML' started by johnmmcparland, Apr 9, 2009.

  1. 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></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 [ ] *
    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
     
    johnmmcparland, Apr 9, 2009
    #1
    1. Advertising

  2. Martin Honnen, Apr 9, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,550
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,268
    Stanimir Stamenkov
    Apr 25, 2005
  3. Replies:
    3
    Views:
    2,875
  4. -saarland.de
    Replies:
    1
    Views:
    567
    Joe Kesselman
    Nov 21, 2006
  5. Arvin Portlock
    Replies:
    0
    Views:
    151
    Arvin Portlock
    Jun 20, 2005
Loading...

Share This Page