XML elements can be expanded, and they are associated.
XML elements have simple naming rules.
XML elements can be expanded.
XML documents can be extended while carrying more information.
See the following XML note example:
<Note>
<To> Lin </to>
<From> Ordm </from>
<Body> Don't forget me this weekend! </Body>
</Note>
Let's imagine a software that can read this XML document and interpret the XML elements (<to>, <from>, and <body>). The possible output is as follows:
MESSAGE
To: Lin
From: Ordm
Don't forget me this weekend!
Let's imagine that if Ordm, the author of the note, adds some additional information to this XML document, as shown below:
<Note>
<Date> 2002-12-24 </date>
<To> Lin </to>
<From> Ordm </from>
<Heading> Reminder <Body> Don't forget me this weekend! </Body>
</Note>
Will the original application be interrupted or crashed?
No. The application still Correctly interprets <to>, <from>, and <body> and generates the same output.
XML documents can be expanded!
XML elements are interrelated.
XML elements are the relationship between parent elements and child elements.
To better understand XML terms, you must understand the relationship between XML elements and how the element content is described.
Imagine a book like this:
Signature: XML Guide
Chapter 1: Introduction to XML
What is HTML?
What is XML
Chapter 2: XML syntax
The XML element must have an end mark.
XML elements must be correctly nested
We can use XML documents to describe this book:
<Book>
<Title> XML guide </title>
<Prod id = "33-657" media = "paper"> </prod>
<Chapter> introduction to XML
<Para> what is HTML </para>
<Para> what is XML </para>
</Chapter>
<Chapter> XML syntax
<Para> the XML element must have an end mark. </para>
<Para> XML elements must be correctly nested </para>
</Chapter>
</Book>
In the code above, the Book element is the root element of the XML document, and the title and chapter elements are child elements of the book element. The Book element is the parent element of the title element and the chapter element. The title, prod, and chapter elements are level elements because they both have the same parent element.
XML Element Content
XML elements have different contents.
An XML element refers to the content between the start tag and the end tag of the element.
XML elements include element content, mixed content, simple content, or empty content. Each element can have its own attributes.
In the above example, the book element has the element content, so the book element should contain other elements. The Chapter element contains a mixture of text and other elements. The para element has simple content because it contains only simple text. The prod element has blank content because it does not carry any information.
In the preceding example, only the prod element has attributes. The id attribute value is 33-657, and the media attribute value is paper.
XML Element naming
The XML element name must follow the following rules:
The element name can contain the child mother, number, and other characters.
The element name cannot start with a number or punctuation.
The element name cannot start with XML (or xml, Xml, xMl.
The element name cannot contain spaces.
You must pay attention to the following simple rules when creating XML elements:
Any name can be used without any reserved words (except XML), but the element name should be readable. It is a good choice to use underscores for names.
Example: <first_name>, <last_name>.
Avoid "-", "." as possible, because it may cause confusion.
If you want the element name to be long, it should not be too exaggerated. The naming rule should follow the simple and easy-to-read principle. For example, <book_title> is a good name, while <the_title_of_the_book> is a big headache.
XML documents often correspond to data tables. We should try our best to keep the names of fields in the database consistent with those in the corresponding XML documents, so that data transformation can be convenient.
Non-English/character/string can also be used as the name of an XML element. For example, <blue ideal> <classic Forum> is a completely legal name. However, some software may not support such naming, so try to use English letters for naming.
Do not use ":" in XML Element naming, because the XML namespace uses this special character.