Cheat Sheet

XML For Dummies

From XML For Dummies, 4th Edition by Lucinda Dykes, Ed Tittel

XML is a markup language that builds web pages. Before you start using XML, study the difference between a valid and well-formed document, how to create DTD (Document Type Definition) elements, and basic schema declarations to build an XML document. You'll also want to understand regularly used reserved characters, as well as which web browsers best support XML and style sheets.

Valid Versus a Well-Formed XML Document

In XML, a valid document must conform to the rules in its DTD (Document Type Definition) or schema, which defines what elements can appear in the document and how elements may nest within one another. If a document isn’t well-formed it doesn’t go far in the XML world so you need to play by some very basic rules when creating an XML document. A well-formed document must have these components:

  • All beginning and ending tags match up. In other words, opening and closing parts must always contain the same name in the same case: <tag> . . . </tag> or <TAG> . . . </TAG>, but not <tag> . . . </TAG>.

  • Empty elements follow special XML syntax, for example, <empty_element/>.

  • All attribute values occur within single or double quotation marks: <element id="value"> or <element id='value'>.

Rules for Creating Document Type Definition, or DTD, Elements

Basically, you prepare and use a Document Type Definition (DTD) to add structure and logic, making it easier to ensure that all essential features are present — in the right order — in your XML document. You may develop many rules in your DTD that control how elements can be used in an XML document.

Symbol Meaning Example
#PCDATA Contains parsed character data or text <element (#PCDATA)>
#PCDATA, element-name Contains text and another element; #PCDATA is always listed first in a rule <element (#PCDATA, child)*>
, (comma) Must use in this order <element (child1, child2, child3)>
| (pipe bar) Use only one element of the choices provided <element (child1 | child2 | child3)>
element-name (by itself) Use one time only <element (child)>
element-name? Use either once or not at all <element (child1, child2?, child3?)>
element-name+ Use either once or many times <element (child1+, child2?, child3)>
element-name* Use once, many times, or not at all <element (child1*, child2+, child3)>
( ) Indicates groups; may be nested <element (#PCDATA | child)*> or <element ((child1*, child2+, child3)* | child4)>

Basic XML Schema Declarations

An XML Schema document is built of a series of declarations, which gives very detailed information and makes sure the information contained in the XML document is in the correct form.

Declaration Name Purpose Syntax
Schema Identifies the language the schema uses <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Element Defines an element <xsd:element name="name">
Attribute Defines an attribute <xsd:attribute name="name" type="type">
Complex type Defines an element that contains other elements, contains attributes, or contains mixed content (elements and text) <xsd:complexType>
Simple type Creates a constrained datatype for an element or attribute value <xsd:simpleType>
Sequence compositor Specifies that attributes or elements within a complex type must be listed in order <xsd:sequence>
Choice compositor Specifies that any one of the attributes or elements within a complex type can be used <xsd:choice>
All compositor Specifies that any or all attributes or elements within a complex type can be used <xsd:all>
Annotation Contains documentation and/or appInfo elements that provide additional information and comments about the schema document <xsd:annotation>
Documentation Provides human-readable information within an annotation <xsd:documentation>
Application information Provides computer-readable information within an annotation <xsd:appInfo>

Common Reserved Characters in XML

Some entities are reserved for internal use in XML and need to be replaced with character references in your content. These five commonly used internal entities are already defined as part of XML and ready for you to use:

Character Reference
< &lt;
> &gt;
& &amp;
' &apos;
" &quot;

Browser Support for XML and Style Sheets

Web browser support for XML and style sheets — CSS and XSLT — is varied and sometimes less-than reliable. Research your options for web browsers so you know which browsers support which requirements and you choose how to use XML and web browsers in your XML solution.

Browser XML? CSS1? CSS2? XSLT 1.0?
Amaya 9.0 Yes Yes No No
Internet Explorer 6.0 Yes Yes Yes Yes
Mozilla 1.7.5 Yes Yes Yes Yes
Mozilla Firefox 1.0 Yes Yes Yes Yes
Netscape Navigator 7 Yes Yes Yes Yes
Opera 7 Yes Yes Yes No
blog comments powered by Disqus
Advertisement

Inside Dummies.com