- Escaping XML Data
- XML Encoding
- XML 1. 0 EBNF
- XML 1.1 EBNF
- Byte Order Marker
- XML Schemas
- XML Mixed Content
- Describing Complex Structures in XML
An XML Element is the basic construct within an XML Document.
XML Element Examples
In practice this means an XML element can look like the following examples
Element with no content
There is a distinct difference between an empty element and an element with no content, however very few parsers choose to interpret them differently.
Element with text
Typically used to hold the value for a property
Element with Attributes
<MyElement myAttribute="attribute value">Some Text</MyElement>
Attributes typically enrich to the data contained within the element, i.e. define the language the text is in, provide unique ID by which the element can be referenced elsewhere within the document etc.
Attributes are typically considered to contain secondary/meta information, although there are no hard and fast rules.
Element with Child Elements
<MyElement> <ChildElement/> </MyElement>
By nesting elements complex hierarchies of data can be constructed. However these hierarchies are tree like. When you start placing real world data in them you quickly hit problems sharing entities between different branches of a tree. These issues can be overcome using unique ID's and references. See Describing Complex Structures in XML.
Element with Mixed Data
<MyElement>Some <b>Mixed</b> Data</MyElement>
Mixed data can contain text and child elements within the containing element. This is typically only used to mark up data (HTML etc).
Its typically only used to hold mark-up/formatted text entered by a person, it is typically not he best choice for storing machine readable data as adds significant complexity to the parser. Where possible it should be avoided.
Namespaces are a concept introduced when an XSD Schema is used, it allows complex XML documents to be broken data down by namespaces.
A namespace is either applied to an element using an aliased prefix
Or via a default namespace declaration
Namespaces are complex and discussed in more detail under XML Namespaces
If you need to put control characters (<,>,&,",') into an elements text value, this could cause the parser to miss understand the resulting document, in order to prevent this the values need to be escaped, see Escaping XML Data.
The syntax for an element is described by the W3C as using EBNF as follows.
 element ::= EmptyElemTag | STag content ETag  STag ::= '<' Name (S Attribute)* S? '>'  Attribute ::= Name Eq AttValue  ETag ::= '</' Name S? '>'  content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*  EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'