XML Guide--xml elements

Source: Internet
Author: User
Tags date closing tag empty mixed
Xml
XML elements can be extended and have associations between them.
XML elements have simple naming rules.



XML elements can be extended
XML documents can be extended to carry more information.
Take a look at 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 reads this XML document and interprets the XML elements (<to&gt, <from&gt, and <body>), and the possible output is as follows:
Message
To:lin
From:ordm
Don ' t forget me this weekend!

Let's imagine if the author of the note ORDM added some additional information to the XML document, as follows:
<note>
<date>2002-12-24</date>
<to>Lin</to>
<from>Ordm</from>
<body>don ' t forget me this weekend!</body>
</note>


Does the original application break down or crash?
No. The application will still correctly interpret <to&gt, <from&gt, and <body> elements, and produce the same output.
XML documents can be extended!



XML elements are related to each other
An XML element is a relationship between a parent element and a child element.
To better understand XML terminology, you must understand how the relationships between XML elements are, and how the content of the elements is described.
Imagine having such a book:
Branding: XML Guide
Chapter One: Introduction to XML
What is HTML
What is XML
Chapter II: XML Syntax
XML element must have a closing tag
XML elements must be nested correctly


We can use an XML document to describe this book:
<book>
<title>xml Guide </title>
<prod id= "33-657" media= "paper" ></prod>
Introductory Introduction to <chapter>xml
<para> What is html</para>
<para> What is xml</para>
</chapter>
<chapter>xml syntax
The <para>xml element must have an end tag </para>
The <para>xml element must be properly nested </para>
</chapter>
</book>


In the above code, the book element is the root element of the XML document, and the title element and the chapter element are child elements of the book element. The book element is the parent element of the title element and the chapter element. The title element, the Prod element, and the chapter element are lateral elements because they all have the same parent element.



Content of XML elements
XML elements have different content.
An XML element refers to this part of the element from the beginning of the elements to the closing tag.
XML elements have element content, mixed content, simple content, or empty content. Each element can have its own properties.
In the example above, the book element has element content, and the book element should contain other elements. The chapter element has mixed content because it contains text and other elements. The para element has a simple content, because it has only simple text inside it. The PROD element has empty content because he does not carry any information.
In the above example, only the PROD element has attributes, and the id attribute value is the 33-657,media property value is paper.



XML element naming
XML element naming must conform to the following rules:
The name of an element can contain a child, a number, and other characters.
The name of an element cannot begin with a number or a punctuation mark.
The name of an element cannot be in Xml (or xml,xml,xml ...) Beginning.
The name of an element cannot contain spaces.
The XML element of your own invention must also note the following simple rules:
Any name can be used, no reserved word (except XML), but should make the name of the element readable, the name of the use of underline is a good choice.
For example: <first_name>, <last_name>.
Try to avoid the use of "--", "." Because it may cause confusion.
As long as you like the element's name can be very long, but also do not exaggerate oh. Naming should follow the principle of easy reading, such as:<book_title> is a good name, and <the_title_of_the_book> is verbose.
XML documents tend to correspond to data tables, and we should try to keep the names of the fields in the database consistent with the names in the corresponding XML documents, which makes it easy to transform data.
Non-English/character/string can also be used as XML element name, for example < blue ideal >< Classic Forum > This is all perfectly legal name. But some software does not support this kind of naming very well, so try to use English alphabet to name.
Do not use ":" in XML element naming because XML namespaces require this very special character.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.