Beruflich Dokumente
Kultur Dokumente
XML
BY SHARON L. HOFFMAN AUGUST 2005
XML syntax and how XML compares with languages used for related tasks.
XML
is a key technology for sharing data between business entities because it bridges different ways of storing and referencing data. Although XML can be described as a language, the extensible nature of XML means that its more correctly classified as a standard. Many interrelated standards (for a list, see Essential XML Standards on page 4) complement XML and expand its capabilities. XML is also a fundamental building block for other standards. For example, many Web-services standards, such as Simple Object Access Protocol (SOAP) and Web Services Description Language (WSDL), are based on XML. To give you a sense of how you might use XML in your own applications, lets start with a quick look at
XML in Context
An XML document is made up of XML elements. Each element contains a starting tag, an ending tag, and (usually) data nested between the two tags. By choosing descriptive names for elements, you can make your XML documents more human-readable and therefore self-documenting. In Figure 1, the highlighted line is a single element called product_code. If a document contains more than one element of the same type, the tags will be repeated for each element as shown for the product_code and requested_qty elements in Figure 1. For more information about XML syntax see Essential XML Syntax and Terminology on page 3. Repeating the data description for every element means that XML documents are entirely self-contained you wont need to refer to a database layout, for example. However, the overhead of repeating all the element-description information Figure 1: Sample XML document quickly becomes unwieldy. As a result, <?xml version="1.0" encoding="UTF-8"?> most developers prefer using data<inventory_inquiry> description languages (e.g., SQL, DDS) <customer_reference>bike component availability</customer_reference> <date_required>9/1/2005</date_required> to define databases. However, XML shines <customer> <customer_name>Acme Company</customer_name> in data-transfer applications that involve <contact_name>Sharon Hoffman</contact_name> relatively small amounts of data (these are <contact_email>shoffman@iseriesnetwork.com</contact_email> </customer> typically single transactions such as an <requested_products> inventory inquiry or a purchase order). <product_code>12345</product_code> <requested_qty>5</requested_qty> Data transfer is by far the most common <product_code>67892</product_code> XML application in iSeries environments. <requested_qty>25</requested_qty> </requested_products> However, you can also use XML to add </inventory_inquiry> meaning to text within documents. Used in this way, XML becomes a powerful
The following nesting is syntactically correct, although it doesnt make much sense:
<customer_name> <first_name>Sharon
Elements can contain one or more attributes. In many cases, the XML designer may choose whether to use elements or attributes to define a particular structure. As a rule of thumb, attributes should be used for information that is not integral to the element. An element cannot contain more than one attribute with the same name. Both starting and ending tags are required for all elements except empty elements. Empty elements occur most often when an element is completely defined by its attributes. Elements must be properly nested (i.e., once an inner element tag is opened, it must be closed before any outer tags).
8 9 10
The outermost element in any XML document is referred to as the root element. The root element may be preceded by a document declaration and processing instructions. Built-in XML entities are used to include a character that has special meaning in XML (e.g., a greater-than sign) within XML content. You can also define additional entities as short-hand for text and structures that you use repeatedly. An XML document that has correct syntax is well formed. An XML document that conforms to the structure defined by its Document Type Definition (DTD) or schema is valid. It is possible for an XML document to be well formed but invalid, but the reverse is not possible.
5 6
11 12
Figure 2:A DTD generated by WDSc for the XML document in Figure 1
The CoverPages
The XML CoverPages include XML news, background material, and technical tips. xml.coverpages.org
DevX.com
Two IBM white papers illustrate how to process XML documents using RPG or Cobol: Parsing XML documents using the new V5R3 ILE COBOL syntax
www-1.ibm.com/servers/enable/site/education/abstracts/3db2_abs.html
XML Interface for RPG maps XML into DB2 UDB for iSeries
www-1.ibm.com/servers/enable/site/education/ibo/record.html?xmlface
XML.com
OReilly Media, Inc., a premier technical book publisher, maintains this XML information site. xml.com
Figure 3:An XML schema generated by WDSc for the XML document in Figure 1
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="contact_email" type="xsd:string"/> <xsd:element name="contact_name" type="xsd:string"/> <xsd:element name="customer"> <xsd:complexType> <xsd:sequence> <xsd:element ref="customer_name"/> <xsd:element ref="contact_name"/> <xsd:element ref="contact_email"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="customer_name" type="xsd:string"/> <xsd:element name="customer_reference" type="xsd:string"/> <xsd:element name="date_required" type="xsd:string"/> <xsd:element name="inventory_inquiry"> <xsd:complexType> <xsd:sequence> <xsd:element ref="customer_reference"/> <xsd:element ref="date_required"/> <xsd:element ref="customer"/> <xsd:element ref="requested_products"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="product_code" type="xsd:string"/> <xsd:element name="requested_products"> <xsd:complexType> <xsd:sequence maxOccurs="unbounded" minOccurs="1"> <xsd:element ref="product_code"/> <xsd:element ref="requested_qty"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="requested_qty" type="xsd:string"/> </xsd:schema>
Explore XML
XML is a powerful tool for communicating data between applications using different databases and running on different platforms, and it is rapidly becoming the medium of choice for transaction-level data transfer. XML can also organize information within a document, thus making it easier to modify and search large amounts of text. For all its strengths, XML is still a relatively new technology with a maze of confusing, and sometimes competing, standards. To take advantage of XML, it helps to have a clearly defined goal and the flexibility to experiment with various tools and techniques. Its also useful to understand how other businesses are using XML. To explore the opportunities XML offers, visit the Web sites listed in Essential XML Resources on page 5. Sharon L. Hoffman is a senior technical editor for iSeries NEWS.