The sample Order document is designed for a purchase order application. Customers submit orders, which are identified by a date and a customer ID. Each order item has an item ID, an item name, a quantity, and a unit designation.
An order document might display on screen like this:
ORDER
Date: July 4, 1999
Customer ID: 123
Customer Name: Acme Alpha
Items:
Item ID |
Item Name |
Quantity |
---|---|---|
987 |
Coupler |
5 |
654 |
Connector |
3 dozen |
579 |
Clasp |
1 |
A possible XML representation of the data for the order is:
<?xml version="1.0"?> <Order> <Date>1999/07/04</Date> <CustomerId>123</CustomerId> <CustomerName>Acme Alpha</CustomerName>
<Item> <ItemId> 987</ItemId> <ItemName>Coupler</ItemName> <Quantity>5</Quantity> </Item>
<Item> <ItemId>654</ItemId> <ItemName>Connector</ItemName> <Quantity unit="12">3</Quantity> </Item>
<Item> <ItemId>579</ItemId> <ItemName>Clasp</ItemName> <Quantity>1</Quantity> </Item>
</Order>
The XML document for the order data consists of these parts:
The XML declaration, <?xml
version=“1.0”?>
, which
identifies Order as an XML document.
XML documents are represented as character data. In each document, the character encoding (character set) is specified, either explicitly or implicitly. To explicitly specify the character set, include the character set in the XML declaration. For example:
<?xml version=”1.0” encoding=”ISO-8859-1”>
If you do not include the character set in the XML declaration, the default, which is UTF8, is used. For example:
<?xml version=”1.0”?>
When the default character sets of the client and server differ, Sybase IQ bypasses normal character set translations so that the declared character set continues to match the actual character set. See “Character sets and XML data”.
User-created element tags such
as <Order>…</Order>
, <CustomerId>…</CustomerId>
, <Item>….</Item>
.
In XML documents, all opening tags must have a corresponding closing
tag.
Text data such as “Acme Alpha,” “Coupler,” and “579.”
Attributes embedded in element tags such
as <Quantity unit = “12”>
. This
kind of coding allows you the flexibility to customize elements.
A document with these parts, and with the element tags strictly nested, is called a well-formed XML document. Note that in the example above element tags describe the data they contain, and the document contains no formatting instructions.