This sample Order document is designed for a purchase order application. Customers submit orders, which are identified by a date and a customer ID. Each o rder item has an item ID, an item name, a quantity, and a unit designation.
It might display on your screen like this:
ORDER
Date: July 4, 2003
Customer ID: 123
Customer Name: Acme Alpha
Items:
Item ID |
Item Name |
Quantity |
---|---|---|
987 |
Coupler |
5 |
654 |
Connector |
3 dozen |
579 |
Clasp |
1 |
The following is one representation of this data in XML:
<?xml version="1.0"?> <Order> <Date>2003/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 has two unique characteristics:
The XML document does not indicate type, style, or color for specifying item display.
The markup tags are strictly nested. Each opening tag (<tag> ) has a corresponding closing tag (</tag>).
The XML document for the order data consists of four main elements:
The XML declaration, <?xml version=“1.0”?>, identifying “Order” as an XML document.
The XML declaration for each document specifies the character encoding (character set), either explicitly or implicitly. XML represents documents as character data.To explicitly specify the character set, include it 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, XML in Adaptive Server uses the default character set, UTF8.
When the default character sets of the client and server
differ, Adaptive Server bypasses normal character-set translations.
The declared character set continues to match the actual character
set. See “XML Support for I18N”.
User-created element tags, such as <Order>…</Order>, <CustomerId>…</CustomerId>, <Item>….</Item>.
Text data, such as “Acme Alpha,” “Coupler,” and “579.”
Attributes embedded in element tags, such as <Quantity unit = “12”>. This embedding allows you to customize elements.
If your document contains these components, and the element tags are strictly nested, it is called a well-formed XML document. In the example above, element tags describe the data they contain, and the document contains no formatting instructions.
Here is another example of an XML document:
<?xml version="1.0"?> <Info> <OneTag>1999/07/04</OneTag> <AnotherTag>123</AnotherTag> <LastTag>Acme Alpha</LastTag>
<Thing> <ThingId> 987</ThingId> <ThingName>Coupler</ThingName> <Amount>5</Amount> <Thing/>
<Thing> <ThingId>654</ThingId> <ThingName>Connecter</ThingName> </Thing>
<Thing> <ThingId>579</ThingId> <ThingName>Clasp</ThingName> <Amount>1</Amount> </Thing> </Info>
This example, called “Info,” is also a well-formed XML document, and has the same structure and data as the XML Order document. However, it would not be recognized by a processor designed for Order documents because the document type definition (DTD) that Info uses is different from that of the Order document. For more information about DTDs, see “XML document types”.