XML technologies / XML / Python & XML / XML basics / The structure of XML
(Excerpt from "Python & XML" by Christopher A. Jones & Fred L. Drake, Jr.)
The basic structure of an XML document is simple. Most of it can be reduced to a few straightforward components. Consider the following:
<?xml version="1.0"?>
<PurchaseOrder>
<account refnum="2390094"/>
<item sku="33-993933" qty="4">
<name>Potato Smasher</name>
<description>Smash Potatoes like never before.</description>
</item>
</PurchaseOrder> In this example, the first line, beginning with the characters <?, is the XML declaration. It specifies the XML version being used and may also contain information about the document’s character encoding. The text beginning with <PurchaseOrder> (purchase order) and ending with </PurchaseOrder> is an XML element. An element must have an opening and a closing tag , or the opening tag must end with the characters /> if it is to be an empty element. The second example shown here (line 3) is an empty element ending with />. The element is opened, contains two other elements and is then closed. The expression sku="33-993933" is an attribute named sku, with its Value 33-993933 in quotation marks. An element can have as many attributes as necessary. Both elements, name and description, are followed by character data or text. Finally, the elements are closed and the document ends.
The rest of this chapter examines the relevant parts of the XML specification and highlights the most important points to know when working with Python and XML.
Copyright © 2002 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "Python & XML" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top