Appendix A. XML Reference

   

XML Elements

Elements are the basis of XML documents. Indeed, an XML document is essentially a tree of elements. Elements are made of the following:

  • A name

  • An optional content

  • An optional list of attributes

The following is a library element made up of two loan elements. Each loan in turn contains a member and a title element. loan elements have a date attribute, whereas member and title contain text:

 <library>       <loan date="2000-03-27">          <member>Jack Smith</member>          <title>XML by Example</title>       </loan>       <loan date="2000-03-12">          <member>John Doe</member>          <title>Applied XML Solutions</title>       </loan>    </library> 

Unlike HTML, no element is predefined by XML. It is up to you, the developer, to create tags that are meaningful in your application.

Element Name

The element name must start with a Unicode letter, followed by zero or more Unicode letters or digits. Also, spaces are not allowed. Names are case sensitive and cannot start with the three letters XML (upper- or lowercase).

In the document, the element name appears within tags (start tag and end tag). The tags surrounds the content, as in

 <title>Applied XML Solutions</title> 

Content

If an element has no content, it is said to be empty. Non-empty elements contain text, other elements, or a combination of both. In other words, elements can nest to form a tree.

Empty elements have a simplified syntax where the slash ( / ) from the end tag migrates at the end of the start tag:

 <book isbn='0-672-32054-1'/> 

Attribute

An attribute is made up of a name and a value attached to an element. Attribute names follow the same rules as element names.

Attributes appear in the element's start tag. The element name and its value are separated by an equal sign, and the value is located between single or double quotes. For example

 <book isbn='0-672-32054-1'/> 

or

 <loan date="2000-03-12">       <member>John Doe</member>       <title>Applied XML Solutions</title>    </loan> 

Predefined Attributes

Two attributes are predefined by the XML standard:

  • xml:lang , which is the content language

  • xml:space , which indicates that spaces must be preserved in the content of the element

   


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net