Latihan XML-Schema Group
Latihan XML-Schema Group
in an XML Schema
Problem Statement
The customer details of CyberShoppe need to be stored in a central repository. To enable
this, the computerized data needs to be collated from the branch offices and maintained at
a central location. This data has to be made available to various sections, such as the
Accounts and the Sales sections of various branches, irrespective of the hardware and
software platforms used. After collating the customer data, the head office needs to verify
that the complete information has been made available and is stored in a consistent
format.
Customer data includes the customer ID, first name, last name, and contact information,
such as the address and phone number. A customer may provide residential or official
contact information.
Solution
To solve the preceding problem, perform the following tasks:
1. Identify the elements and attributes required to store the data.
2. Declare a group of elements and attributes in a schema.
3. Create an XML document to store the data.
4. Validate the XML document against the schema.
Task 1: Identifying the Elements and Attributes Required to Store the Data
The following table lists the elements required to store the customer details in an XML
document.
Element Description
CUSTOMERDATA Acts as the root element for all other elements that are used in the
XML document.
CUSTOMER Represents the customer details, such as the first name, last name,
and contact information for each customer.
PHONE Represents the phone number of the residence or the office for a
customer. This element will be used as a child element of
CONTACTINFO.
The following table list the attribute required to store the customer details in an XML
document.
Attribute Description
CUSTOMERID Represents the customer ID.
To create groups of elements and attributes in the given scenario, type the following code
in Notepad, and save the file as customer.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CUSTOMERDATA" type="cdata"/>
<!-- Declaration for the "cdata" complex type -->
<xsd:complexType name="cdata">
<xsd:sequence>
To store the data about CyberShoppe customers, type the following code in Notepad, and
save the file as customer.xml:
<?xml version="1.0"?>
<CUSTOMERDATA>
<CUSTOMER CUSTOMERID="C001">
<FIRSTNAME> Steve </FIRSTNAME>
<LASTNAME> Shaw </LASTNAME>
<CONTACTINFO>
<RESIDENCE>
<ADDRESS> 15, LIONS STREET, BOSTON </ADDRESS>
To verify that the customer data stored in customer.xml conforms to the schema defined
in customer.xsd, perform the following steps:
1. Open Index.htm from the Learning Environment folder.
2. Click the Schema Validator link. This will open the XML Schema Validator
Module form.
3. In the XML - Schema Validator Module form, type the path for customer.xml in
the Enter the XML File Name text box and type the path for customer.xsd in the
Enter the XSD File Name text box.
4. Click the Validate button.
If there are errors in the XML document, an appropriate error message is displayed.
Otherwise, the message, No Error, is displayed.