In the example above <sandwich>, <condiment>, and all tags within <> are elements.
Elements can be nested within each other infinitely deep.
"price" and "slices" are attributes of their respective elements.
XML must be well formed to be porcessed:
All tags are closed: <bread>Rye</bread>,
or <bread/> which denotes an empty element.
Elements must be closed on the same level they start.
<sandwich><meat></sandwich></meat> is not well formed.
All attributes are within single or double quotes.
The structure of a particular XML document can be described with Document Type Definitions (DTD) or schemas. Instances of that document can then be validated against the corresponding DTD or schema.
Why use XML?
Flexible hierarchical data formatting language that can easily be read by humans as well as programs.
Readily available tools for document creation, parsing, and validation.
Plaform and programming language neutral.
The Java API for XML Processing (JAXP) defines a standard interface for using XML in Java programs. There are several implementations of this API, including Xerces from the Apache Group and Crimson from Sun.