Introduction to Basic concepts and syntax of XML markup language (Figure)

Source: Internet
Author: User
Tags xml attribute tutorialspoint
This article mainly introduces the basic concepts and syntax of XML markup language. XML is also widely used as a tag data exchange format, for more information about the basic concepts and syntax of XML markup language, see this article. XML is also widely used as a tag data exchange format, for more information, see


XML indicates the Extensible Markup Language. It is a text-based markup language derived from the standard universal Markup Language (SGML ).

The XML tag identifies the data and is used to store and organize data, instead of specifying how to display it, which is used to display data like HTML. In the near future, XML will not replace HTML, but it introduces the possibility by using many successful features in HTML.

Here there are three important characteristics of XML, which makes it useful for a variety of systems and solutions:

XML is extensible: XML allows us to create our own custom descriptive labels or languages suitable for applications.
XML carries data but does not render it: XML allows us to store data, no matter how it is presented.
XML is a public standard: XML is developed by organizations called the World Wide Web Consortium (W3C) and can be used as an open standard.


Use of XML
The brief list of XML usage illustrates everything:

XML can work behind the scenes to simplify creating HTML documents for large websites.
XML can be used to exchange information between organizations and systems.
XML can be used to unload and reload databases.
XML can be used to store and organize data and customize data processing requirements.
XML can easily merge style sheets to create almost any desired output.
In fact, any type of data can be expressed as an XML document.


What is a tag?
XML is a markup language that defines a set of rules for coding documents in human-readable and machine-readable formats. So what is a markup language? A tag is the information that is added to a document to improve its meaning in some way. it identifies the part and how it is associated with each other. More specifically, a markup language is a set of symbols that can be placed in the document text to divide and Mark certain parts of the document.

The following example shows what the XML mark embedding a piece of text looks like:

     
  
   Hello, world!
  
 

This clip contains a markup symbol or a tag, such ... And ... . Tag And The start and end of the XML code snippet. Tag And Wrap the text Hello world !.

Is XML a programming language?
A programming language used to create a computer program consists of syntax rules and its own vocabulary. These programs instruct the computer to execute specific tasks. XML is not qualified to be a programming language because it does not execute any computing or algorithms. It is usually stored in simple text files and processed by special software that can interpret XML.

XML syntax
The following is a complete XML document:

 
 
  
   Tanmay Patil
  
  
   TutorialsPoint
  
  
   (011) 123-4567
  
 

You can note that the preceding example contains two types of information:

Tag, such .
Text or character data, such as _ Tutorials Point and (011) 123-4567 _.
Describes the syntax rules for writing different types of tags and text in XML documents:

Let's take a closer look at each of the components:

XML declaration
The XML document can have an optional XML declaration. It can be written as follows:

 


Here, version is the XML version. encoding specifies the character encoding used in the document.

XML declaration syntax rules

The XML statement is case sensitive and must be" ", Where" xml "is in lowercase.
If the document contains an XML declaration, it must be the first statement in the XML document.
The XML declaration must be the first statement in the XML document.
You can use an HTTP protocol to overwrite the value of encoding specified in the XML declaration.


Tags and elements
The structure of an XML file consists of several XML elements, also known as XML nodes or XML labels. The XML element name is closed using angle brackets, as shown below:

 

Syntax rules for tags and elements

Element syntax: Each XML element must be closed or contain the start and end elements, as shown below:

 
  ....
 

Or simply, like this:

 

Element nesting: an XML element can contain multiple XML elements as its child elements, but the child elements cannot overlap. For example, the end tag of an element must have the same name as the recently matched start tag.

The following example shows incorrect nested labels:

 
 
  
   TutorialsPoint   
   
  
 

The following example shows the correct nested labels:

 
 
  
   TutorialsPoint
  
  
 

Root element: an XML document has only one root element. For example, the following is an incorrect XML document, because the x and y elements appear on the top layer without a root element:

 
  ...
 
 
  ...
 

The following example shows the XML document in the correct format:

     
  
   ...
      
  
   ...
  
 

Case sensitive: the names of XML elements are case sensitive. This means that the start and end tags of the element must be the same in case.

For example And __ It is different.

Attribute
Attribute specifies an attribute for an element using a name/value pair ). An XML element can have one or more attributes (attributes ). For example:

Tutorialspoint!

Here, href is the property name, and # is the property value.

XML attribute syntax rules

XML attribute names are case sensitive (different from HTML ). That is to say, HREF and href are considered to be two different XML attributes.
There cannot be two identical attributes in the syntax. The following example shows the incorrect syntax, because attribute B is specified twice:

....

The attribute name definition does not contain quotation marks, and the attribute value must be displayed in the quotation marks. The following example demonstrates the incorrect XML syntax:

....

In the preceding syntax, the property value is not defined in the quotation mark.

XML Reference
References usually allow us to add or include additional text in XML documents. The reference always starts with the symbol "&", which is a reserved character and ends with the symbol. There are two types of references in XML:

Object reference: a name is included between the start and end delimiters of an object reference. For example, "&" indicates the name. This name usually points to a predefined text string or tag.

Character references: these include references. for example, A contains A hash mark ("#") followed by A number. This number always points to the Unicode code of a character. Here, 65 points to the letter "".

XML text
The names of XML elements and XML attributes are case sensitive. This means that the start and end tags of the element must be in the same case.
To avoid character encoding problems, all XML files should be saved as Unicode UTF-8 or UTF-16 files.
Blank characters, such as spaces, tabs, and line breaks between XML elements and XML attributes are ignored.
Some characters are reserved by the XML syntax. Therefore, you cannot use them directly. To use them, you must use some substitution entities. Some of the following are listed:

The above is the introduction to the basic concepts and syntax of XML markup language (figure). 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.