A detailed introduction to the use of tags and elements in XML

黄舟
Release: 2017-03-10 19:57:25
Original
1827 people have browsed it

This article mainly introduces the use of tags and elements in XML. It is the basic knowledge for introductory learning of XML. Friends who need it can refer to it

tag
us Let's learn about one of the most important parts of XML, XML tags. XML tags are the basis of XML. They define the scope of an element in XML. They can also be used to insert comments, declare settings required for the parsing environment, and insert specific directives.

XML tags can generally be classified as follows:

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

Copy after login

End tag
Every element with a start tag should be closed with a closing tag. Here is an example of a closing tag:

Copy after login

Note that the closing tag contains a slash ("/") in front of the element name.

Empty tag
The text that appears between the start tag and the end tag is called content. Elements with no content are called empty elements. Empty elements are represented in the following two ways:

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


Copy after login

(2) In the true sense The empty element tag looks like this:


Copy after login

The empty element tag can be used for any element that has no content.

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

Rule 1

XML tags are case-sensitive. The following line of code is an example of bad syntax because the two tags are not the same case, which is considered bad syntax in XML.

This is wrong syntax
Copy after login

The following code shows the correct approach, where the opening and closing tag names use the same case.

This is correct syntax
Copy after login

Rule 2

XML tags must be closed in the appropriate order, for example, an XML tag opened inside another element must be closed before the outer element is closed. For example:


    
    This tag is closed before the outer_element   
    
Copy after login

Element
XML elements can be defined as building blocks of XML. Elements can appear as containers that hold text, elements, attributes, media objects, or any of these.

Every XML document contains one or more elements, whose scope is bounded by start and end tags, or an empty element tag to represent an empty element.

Syntax
The following is the syntax for writing an XML element:


....content   
Copy after login

Here

element-name: Represents the name of the element. The names between the opening and closing tags must match.
attribute1, attribute2: It is the element attributes separated by spaces. Attributes define the properties of an element. It associates a name and a string value. Attributes are written in the following form:
name = "value"
Attribute_name_ is followed by an = sign and a string value wrapped in double quotes (" ") or single quotes (' ').

Empty element
The syntax of an empty element (an element with no content) is as follows:


Here is an XML document using various XML elements:



    
Tanmay Patil TutorialsPoint (011) 123-4567
Copy after login

XML Element Rules
XML elements need to follow the following rules:

Element_names can contain any alphanumeric characters. The only tag symbols allowed in names are hyphen (-), underscore (), and period (.).
Element names are case-sensitive. For example, Address, address and ADDRESS are different element names. The opening and closing tags of the
element must be the same.
An element is a container, which can contain text or elements, as you can see in the example above.

The above is the detailed content of A detailed introduction to the use of tags and elements in XML. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!