1.4.2 compiling of XML documents

Source: Internet
Author: User

HTML provides a fixed set of predefined elements that can be used to mark each component of a Web page. XML does not have predefined elements. Users can create their own elements and name them themselves. XML tags can be expanded. You can define new tags as needed. The XML tag is used to describe the structure of the text, rather than to describe how to display the text.
XML defines a set of rules for marking text or documents. You can specify any name for the tag as needed, such as <persons>, <name>, and <birth>. XML tags are case sensitive.

Example 1.10: Create an XML document to save some information.
XML document source code is as follows Ex1-10.xml ):

1: <? Xml version = "1.0" encoding = "GB2312"?>
2: <persons>
3: <person>
4: <name> Li Ming </name>
5: <birth> 06/10/1980 </birth>
6: <telephone> 12345678 </telephone>
7: </person>
8: <person>
9: <name> Zhang mengmeng </name>
10: <birth> 12/11/1981 </birth>
11: <telephone> 88772212 </telephone>
12: </person>
13: </persons>

Note: The sequence number starting from each line is added for illustration. It is not the content of the XML document.
It can be seen that the XML document does not contain format information, but defines tags such as <persons>, <name>, and <birth> to indicate the true meaning of the data. The XML mark is the delimiter <>) and the text enclosed by the delimiter.
Like HTML, tags appear in pairs in XML. For example, <persons>, <name>, and <birth> are marked on, but are located on the back, for example, </persons>, </name>, and </birth> are closed tags. Unlike HTML, closed tags cannot be omitted in XML. In addition, the tag is case sensitive. For example, <persons> and <Persons> are two different tags. The text between a tag and an open or closed tag is combined to form an element. All elements can have their own attributes. The attributes are written in the tag using the "attribute/value" pair.

Example 1.10:
? Row 3: <? Xml version = "1.0" encoding = "GB2312"?>, This statement is an XML declaration, indicating that this document is an XML document and the version of this XML document is 1.0. This statement is optional. xml should be in lower case and? And xml cannot contain any characters (including spaces ).
? The <persons> open tag and </persons> close tag are used in rows 2nd and 13th. The two tags are root tags because all data in this document is included in these two tags. An XML document can only have one root tag. Other tags are layered and nested to form a Tag Tree.
? The <person> open tag and </person> closed tag are used in rows 3rd and 7th to indicate a person's information. In this element, use the <name> flag to indicate the person's name, the <birth> sign to indicate the date of birth, and the <telephone> sign to represent the phone number.
? 8th rows ~ Row 3 defines the information of another person.


BibliographyPrevious sectionNext section

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.