Introduction to the use of labels and elements in XML

Source: Internet
Author: User
This article mainly introduces the use of labels and elements in XML, which is the basic knowledge in XML learning. For more information about the use of tags and elements in XML, see the following article, it is the basic knowledge for getting started with XML. For more information, see

Tag
Let's take a look at the XML tag, one of the most important parts of XML. XML tags are the basis of XML. They define the range of an element in XML. They can also be used to insert comments, declare the settings required for the parsing environment, and insert specific commands.

XML tags can be categorized as follows:

Start Tag
Each starting non-empty XML element is marked as a start tag. The following is an example of a start tag:

 

End tag
Each element with a start tag should be closed using the end tag. The following is an example of an end tag:

 

Note that the end tag contains a slash ("/") before the element name ("/").

Empty tag
The text that appears between the start tag and the end tag is called content. An element without content is called an empty element. Empty elements are represented in the following two methods:

(1) the start tag is followed by an end tag, as shown below:

 

(2) The true empty element label is as follows:

 

Empty element labels can be used for any element without content.

XML tag rules
The following are the rules to be followed when using XML tags:

Rule 1

XML labels are case sensitive. The following line of code is an example of an error syntax. because the two labels are case-insensitive, the syntax is regarded as an error in XML.

This is wrong syntax

The following code shows the correct method. the names of the start and end labels use the same case.

This is correct syntax

Rule 2

XML tags must be closed in the appropriate order. for example, XML tags enabled inside another element must be closed before the external element is closed. For example:

     
  
       This tag is closed before the outer_element       
  
 

Element
XML elements can be defined as XML building blocks. Elements can be expressed as carrying text, elements, attributes, media objects, or containers with these elements.

Each XML document contains one or more elements whose ranges are defined by the start and end tags, or an empty element tag is used to represent an empty element.

Syntax
The syntax for writing an XML element is as follows:

 
  ....content   
 

Here

Element-name: the name of the element. The _ name_between the start and end tags must match.
Attribute1 and attribute2 are the element attributes separated by spaces. Attribute defines the attributes of an element ). It is associated with a name and a string value. Attributes are written as follows:
Name = "value"
Attribute _ name_followed by a = sign and a string value enclosed by double quotation marks ("") or single quotation marks.

Empty element
The syntax for empty elements (elements without content) is as follows:


The following is an XML document that uses different XML elements:

 
             
  
   Tanmay Patil
          
  
   TutorialsPoint
          
  
   (011) 123-4567
      
 

XML element rules
XML elements must follow the following rules:

The element _ name can contain any letter or digit. The only allowed tag characters in the name are hyphens (-), underscores (), and periods (.).
The element name is case sensitive. For example, Address, address, and ADDRESS are different element names.
The start and end labels of the element must be the same.
An element is a container that can contain text or elements, as shown in the preceding example.

The above is the detailed description of the use of tags and elements in XML. For more information, see other related articles in the first PHP community!

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.