XML |
||||||||||||||||||||||
Tags |
||||||||||||||||||||||
An opening tag gives the name of the element, within <> brackets.
|
||||||||||||||||||||||
|
||||||||||||||||||||||
A closing tag is always required. The closing tag has a slash before the name.
The name must be spelled exactly like the opening tag.
The capitalization must be the same.
|
||||||||||||||||||||||
|
||||||||||||||||||||||
You may NOT put spaces before the name. You may put spaces at the end, before the closing > |
||||||||||||||||||||||
|
||||||||||||||||||||||
Elements |
||||||||||||||||||||||
An element is an opening tag, its matching closing tag, and everything contained between them. This example element content is only text. Text is always contained within an element. Text is sometimes called Parsed Character Data or PCDATA. Parsed means that the parser looks at the text to try and find < characters and element tags. PCDATA is an SGML term. XML is derived from the older language: Standard General Markup Language (SGML). An element that only contains text is said to have simple content. |
||||||||||||||||||||||
|
||||||||||||||||||||||
An element that only contains elements is said to have element content. |
||||||||||||||||||||||
|
||||||||||||||||||||||
An element that contains elements and text is said to have mixed content.
|
||||||||||||||||||||||
|
||||||||||||||||||||||
There must be ONE root element in an XML document. All the other elements and all text must be somewhere within the root element |
||||||||||||||||||||||
|
||||||||||||||||||||||
Attributes |
||||||||||||||||||||||
You can put attributes in the start tag of an element (Not in the closing tag at the end of an element).
Put a space before the attribute name,
If you use an attribute, it must always have a value, and the value must always be in quotes The name of the attribute must be unique within the tag where it appears.
Attributes can be coded in any order.
The order of the A, B, and C attributes does not matter in the example. |
||||||||||||||||||||||
|
||||||||||||||||||||||
Names |
||||||||||||||||||||||
Names of elements and attributes must meet the following rules:
Examples: |
||||||||||||||||||||||
|
||||||||||||||||||||||
Whitespace |
||||||||||||||||||||||
In HTML and XHTML, the extra whitespace is stripped out of the text. <p> This paragraph has extra space. </p>
will display in HTML as: |
||||||||||||||||||||||
In XML PCDATA, the whitespace is NOT stripped out.
When you look at this example displayed in a browser,
you will only see a single space, as is done in HTML.
The XML still has the extra spaces,
but the browsers do not show it. |
||||||||||||||||||||||
Empty element |
||||||||||||||||||||||
Sometimes you have an empty element. |
||||||||||||||||||||||
|
||||||||||||||||||||||
Entity and Character references |
||||||||||||||||||||||
Entity references and character references are used to insert
a single character into your document. The following are the only entity references in XML.
You are required to use & for & and < for < everywhere they appear in your document. Otherwise the parser would think they were the start of a tag or of a reference. The other entity references are optional. You are also permitted to use character references for any Unicode character, by using the decimal or hexadecimal number for the character. This example uses #169 or #xA9 to produce the character ©
|
||||||||||||||||||||||
Parsed and unparsed data |
||||||||||||||||||||||
The text in your document is called parsed character data or PCDATA.
This XML text is parsed.
That means the XML parser looks for
If you have a lot of
To make text CDATA, so it will not be parsed,
The character sequence
Look at the source code of the CDATA example.
You will see that the mathematical expression uses
|
||||||||||||||||||||||
Comments |
||||||||||||||||||||||
XML uses SGML comments, just like HTML.
Comments start with
|
||||||||||||||||||||||
|
||||||||||||||||||||||
XML declaration |
||||||||||||||||||||||
The XML declaration tells that this is an XML document.
|
||||||||||||||||||||||
|
||||||||||||||||||||||
Processing Instructions |
||||||||||||||||||||||
Processing instructions are not very important. They look like the XML declaration, except they may appear anywhere in the document, and instead of specifying xml processing, some other name is used to identify your processor, which will be processing the information. The contents can be anything your process needs. The process name must meet the requirements for XML names. Processing instructions are not used very much. |
||||||||||||||||||||||
|
||||||||||||||||||||||
Lecture notes |
||||||||||||||||||||||
Lecture notes are the material used by the instructor in class.
These on-line web pages give most of the information about what you need to do and
how to do it. |
||||||||||||||||||||||
Reference page |
||||||||||||||||||||||
The link is to a summary of the rules for writing well formed XML. You may print this summary for use in this class, if you wish. |
||||||||||||||||||||||