Introduction to basic concepts of XML


Who is HTML’s twin brother? There is no doubt that XML, as a pair of twin brothers, has two basic grammatical similarities, but the external and internal are not equivalent. Although XML is very much like HTML, there are essential differences between them.


XML (eXtensible Markup Language) is an extensible markup language, which is similar to HTML grammar and belongs to markup language. So how do you tell them apart?

1. Design differences
XML is designed to transfer and save data, and its focus is on the content of data. HTML is designed to display data, focusing on the appearance of the data. It can be said that HTML aims at displaying information and XML aims at transmitting information.

2. Grammatical Differences
(1) HTML has a variety of formats, some of which can not appear in pairs, and XML requires all tags to appear in pairs.
(2) HTML tags are fixed and limited in style. XML can be extended in any way, and tag types can be defined by themselves.
(3) HTML can have multiple tag headers, and XML only allows one tag header.
(4) HTML tags are case-insensitive and XML case-insensitive.

II. XML Explanation

Have you ever remembered whether the system configuration document used in the development of the system is an XML document? As the configuration file of the system, it is the main application of xml. At the same time, it can also be used to transfer data in Ajax or Web Services.
2016624150445375.png (634×332)

1. XML History

Before we get to know the basic usage of XML in detail, let’s take a look at the history of markup language.
The predecessor of XML is SGML (The Standard Generalized Markup Language), which is also optimized on the basis of HTML. SGML is a standard after GML has been sorted out, but SGML is a very rigorous text description method, which is too large and complex to understand. At the same time, W3C (World Wide Web Consortium) also found HTML problems, such as: unable to explain other forms of content such as audio-visual files, chemical formulas, and poor performance is not easy to expand, poor elasticity and so on. In order to solve the above problems, experts use SGML to make simple, and develop XML according to the development experience of HTML.    
2016624150514099.jpg (620×456)

2. XML usage

Let’s start with an XML instance

XML/HTML CodeCopy content to clipboard
  1. <?xml version=“1.0” encoding=“utf-8”?>     
  2. <?xml-stylesheet type=‘text/xsl’ href=‘content.xsl’?>     
  3. <book>     
  4.     <List of books>     
  5.         <Computer Books>     
  6.             <bookname isbn=“xxx1234567”><<XMLApplication Daquan>></bookname>     
  7.             <price>39.00</price>     
  8.         </Computer Books>     
  9.     </List of books>     
  10. <! – I added a comment – >     
  11.     <List of books>     
  12.         <Computer Books>     
  13.             <bookname><! [CDATA [Oracle Application Complete’;’;””]></bookname>     
  14.             <price>39.00</price>     
  15.         </Computer Books>     
  16.         <Computer Books>     
  17.             <bookname>Java Application Complete</bookname>     
  18.             <price>39.00</price>     
  19.         </Computer Books>     
  20.     </List of books>     
  21. </book>    

2.1 statement

A well-formed XML file begins with an XML declaration, that is, <? XML version = “1.0” encoding = “utf-8”?> in the example above, which provides basic information about the document. The encoding represents the character encoding method used by the XML file, and the encoding attribute value must be the encoding attribute value in order to preserve the encoding format of the XML document.

2.2 elements

The element is the start tag, the end tag, and everything in between.
Like HTML, XML also has a basic tag structure. The format of tags is the same as HTML tags. The difference is that XML tags must have end tags when they have start tags, and they are case-sensitive. It allows the tag format to be nested, but it must be nested correctly.
XML structure is a tree structure, its content must have only one root element, other elements must be nested in the root element. For example, <book></book> in the example above is the root element.

2.3 Entity Reference

Entity references print some special symbols in the XML document in a specific format, similar to the text in CDATA.

XML/HTML CodeCopy content to clipboard
  1. <book>     
  2.     <List of books>     
  3.         <Computer Books>     
  4.             <bookname isbn=“xxx1234567”><<XMLApplication Daquan>></bookname>     
  5.             <price>39.00</price>     
  6.         </Computer Books>     
  7.     </List of books>     
  8. </book>     
  9. <! – Use IE to open the above code to see the results – > Use IE to open the above code.    

Basic entity references are not detailed.

2.4 Special Labels

CDATA is a special label that enables all content within it to be printed out as text. The forms are as follows:

XML/HTML CodeCopy content to clipboard
  1. <! [CDATA [Text Content]>     
  3. <?xml version=‘1.0’ encoding=‘utf-8’?>     
  4. <List of books>     
  5.         <Computer Books>     
  6.             <bookname><! [CDATA [Oracle Application Complete’;’;””]></bookname>     
  7.             <price>39.00</price>     
  8.         </Computer Books>     
  9. <List of books>    

2.5 Chowder

(1) XML documents are organized by graphs, which is actually a tree structure. IE is often used to open them when they are displayed.
(2) The values of attributes in XML tags must be enclosed in quotes (single or double quotes, but they must be consistent);
(3) XSL format can be used to beautify the display of XML in XML documents with complex internal structure. The format: <? Xml-stylesheet type=’text/xsl’href=’the name of the XML document to be converted. xsl’?>.

Three, pay attention to

1. Statement: <? XML version=”” encoding=”?>;
2. The encoding type should be saved to the corresponding type when it is saved. Don’t forget to choose the type when it is saved.
3. There is only one top element.
4. Case sensitivity;
5. Attribute values must be enclosed in quotation marks (single or double quotation marks);
6. Start and finish.
7. Nested form should be correct.

The basic application of XML is discussed above. XML is very simple. Is XML all about that? Of course not. It’s also a programming language from its basic name. It should have some features of the programming language, such as templates in some languages or APIs in Java. Yes, XML can also define its own grammatical structure. It can write template functions like programming languages, but in XML it is called legitimate XML, which is what we call legitimate XML verified by DTD or Schema.