XML Guide-XML elements

Source: Internet
Author: User
XML elements can be expanded, and they are associated. XML elements have simple naming rules. 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:

  
  
   Lin
   
  
   Ordm
   Don't forget me this weekend! 
 


Let's assume that an XML document can be read and interpreted ( , , And), 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:

  
  
   2002-12-24
   
  
   Lin
   
  
   Ordm
   
  
   Reminder
   Don't forget me this weekend! 
 


Will the original application be interrupted or crashed?
No. The application will still be correctly interpreted , , AndAnd generate 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:

  
  XML Guide 
   
  
   
Introduction to XML
   
    
What is HTML?
    
   
    
What is XML
    
   
  
   
XML syntax
   
    
The XML element must have an end mark.
    
   
    
XML elements must be correctly nested
    
   
 

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.
For example: , .
Avoid "-", "." as possible, because it may cause confusion.
If you want the element name to be long, it should not be too exaggerated. Naming should follow the simple and easy-to-read principle, for example: Is a good name, and Then it looks awkward.
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.
A non-English/character/string can also be used as the name of an XML element, for example <蓝色理想> <经典论坛> These are all completely legal names. 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.

The above is the content of the XML element in the XML Guide. For more information, see The PHP Chinese website (www.php1.cn )!

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.