In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "what is the use of XML". It is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the use of XML?"
History of 1.XML
Gml (1969)-> sgml (1985)-> html (1993)-> xml (1998)
1969 gml (Universal markup language), a data specification designed to communicate between different machines
1985 sgml (Standard Universal markup language)
1993 html (Hypertext markup language, www net)
The html language itself has some defects.
(1) labels cannot be customized
(2) html itself lacks meaning.
(3) html has no real internationalization.
There is an intermediate transition language, xhtml:
Html- > xhtml- > xml
1998 xml extensiable markup language Extensible markup language
two。 Why do you need XML
1. Demand 1
Data communication between two programs?
two。 Demand 2
Give a server, make a configuration file, and when the server program starts, read the port number it should listen to, as well as the user name and password to connect to the database?
In the XML language, it allows users to customize tags. A tag is used to describe a piece of data; a tag can be divided into a start tag and an end tag, and other tags can be used to describe other data between the start tag and the end tag to describe the data relationship.
Common applications of 3.XML
The emergence of 1.XML solves the problem of data transfer between programs:
For example, the data transfer between QQ uses XML format to transfer data, which has good readability and maintainability.
2.XML can be used as a configuration file
It can be said that it is very common for XML files to do configuration files, such as the server.xml,web.xml of our Tomcat server. For example, the structs-config.xml file in our structs, and the hibernate.cfg.xml of hibernate, and so on.
3.XML can act as a small database
XML file can do a small database, is also a good choice, our program may use some often manual configuration of data, if it is not appropriate to read in the database (because this will increase the work of maintaining the database), you can consider directly using XML to do a small database. Reading files directly in this way is obviously faster than reading databases. For example, the XML file is used to save user chat records in msn.
Getting started case: use XML to record a class information.
Yang Guo male 20 Xiao long female 21
We can open it with a browser:
So can our XML be displayed on the web like html? It's OK, it can also be decorated with css, but we don't need it, we just need to use XML to store data.
In this example, if we change the coding of the first line to utf-8 and then open it with a browser, we will report an error. why?
Because the default coding of xml files is ANSI, that is, the code developed by the American National Standards Institute, it has developed different standards according to different countries and regions, so it is GB2312 in China, so we use GB2312 coding will not make an error, and using UTF-8 will report an error.
The solution is to change the XML file to the encoding mode of UTF-8.
4.XML syntax
A XML file is divided into the following sections:
1. Document declaration
two。 element
3. Attribute
4. Annotation
5.CDATA area, special characters
6. Processing instruction (processing instruction)
4.1.XML syntax-document declaration
The XML declaration is placed on the first line of the XML document
The XML declaration consists of the following parts:
Version-documentation conforms to the XML1.0 specification, and we learn 1. 0
Encoding-document character encoding, such as "GB2312" or "UTF-8"
Standalone-whether the document definition is used independently
Standalone= "no" is the default. Yes is used independently, while no is not used independently.
4.2.XML syntax-elements (or tags, nodes)
(1) each XML document must have one and only one root element
The root element is an element that fully includes all other elements in the document
The start tag of the root element should be placed before the start tag of all other elements
The closing tag of the element should be placed after the closing tag of all other elements
(2) the XML element refers to the tags that appear in the XML file. A tag is divided into an opening tag and an ending tag. A tag can be written in the following ways, such as
Contains the tag body:
Www.sohu.com
Not containing the label body:
, abbreviated as:
(3) several sub-tags can also be nested in a tag. However, all tags must be reasonably nested, and cross-nesting is absolutely not allowed, such as
Welcome to www.sohu.com
This kind of situation must be misreported.
(4) for all spaces and line breaks that appear in XML tags, the XML parser will treat them as tag contents. For example, the meaning of the following two paragraphs is different.
Xiaoming
And as follows:
Xiaoming
(5) since spaces and line breaks are treated as raw content in XML, special attention should be paid to writing XML documents.
(6) naming conventions: an XML element can contain letters, numbers, and other visible characters, but must follow the following specifications:
Case sensitive, for example, element P and element p are two different elements
Cannot start with a number or an underscore "_"
Cannot contain spaces within an element
The middle of the name cannot contain a colon (:)
You can use Chinese, but it's not usually used that way.
4.3.XML Syntax-attribute Tom
(1) attribute values are separated by double quotation marks (") or single quotation marks ('). If there are single quotation marks in the attribute values, they are separated by double quotation marks; if there are double quotation marks, they are separated by single quotation marks. What if there are both single quotation marks and double quotation marks in the attribute values? this uses entities (escape characters, similar to spaces in html). XML has five predefined entity characters, as follows:
(2) an element can have multiple attributes, and its basic format is:
(3) A specific attribute name can only appear once in the same element tag.
(4) attribute values cannot include, &, if they must be included, use entities.
4.4.XML Syntax-comment
The comments for XML are similar to those in HTML:
(1) the content of the comments should not appear--
(2) do not put comments in the middle of the tag
(3) comments cannot be nested
(4) comments can be placed anywhere except the mark
4.5.XML syntax-CDATA section
If there is such a requirement, you need to transfer a picture through a XML file, what do you do? In fact, all the files we see on the computer are essentially strings, but they are special binary strings. We can pass the binary string of an image through the XML file, and then parse it into an image. Then the string will contain a large number of special illegal characters such as & or ". At this point, the parsing engine will report an error.
Therefore, some content may not want to be parsed by the parsing engine, but rather treated as raw content, which is used to interpret the entire piece of text as pure character data rather than markup. This is going to use the CDATA festival.
The syntax is as follows:
You can enter any character (except]] > in the CDATA section, but it cannot be nested!
As in the following example, it will not report an error in this case, but it will report an error if it is not included in the cdata section:
Yang Guo-nan 20 4.6.XML Grammar-processing instruction
Processing instruction, referred to as PI (processing instruction). Processing instructions are used to instruct the parsing engine how to parse XML files, as shown in the following example:
For example, we can also use css stylesheets to decorate the XML file, and write my.css as follows:
Name {font-size:80px; font-weight:bold; color:red;} sex {font-size:60px; font-weight:bold; color:blue;} sex {font-size:40px; font-weight:bold; color:green;}
We introduce this css file using processing instructions in the xml file, as follows:
Yang Guo male 20 Xiao long female 21
At this point, when we open the xml file with a browser, we will find that the browser parses a styled view instead of a simple directory tree:
However, XML processing instructions are not required to be mastered, because very few are used.
5. Formal XML documents-Summary
Grammatical norms:
1.XML declaration statement
two。 There must be a root element
3. Tags are case sensitive
4. Attribute values are in quotation marks
5. Mark in pairs
6. Null tag off
7. Elements are nested correctly
History of 1.XML
Gml (1969)-> sgml (1985)-> html (1993)-> xml (1998)
1969 gml (Universal markup language), a data specification designed to communicate between different machines
1985 sgml (Standard Universal markup language)
1993 html (Hypertext markup language, www net)
The html language itself has some defects.
(1) labels cannot be customized
(2) html itself lacks meaning.
(3) html has no real internationalization.
There is an intermediate transition language, xhtml:
Html- > xhtml- > xml
1998 xml extensiable markup language Extensible markup language
two。 Why do you need XML
1. Demand 1
Data communication between two programs?
two。 Demand 2
Give a server, make a configuration file, and when the server program starts, read the port number it should listen to, as well as the user name and password to connect to the database?
In the XML language, it allows users to customize tags. A tag is used to describe a piece of data; a tag can be divided into a start tag and an end tag, and other tags can be used to describe other data between the start tag and the end tag to describe the data relationship.
Common applications of 3.XML
The emergence of 1.XML solves the problem of data transfer between programs:
For example, the data transfer between QQ uses XML format to transfer data, which has good readability and maintainability.
2.XML can be used as a configuration file
It can be said that it is very common for XML files to do configuration files, such as the server.xml,web.xml of our Tomcat server. For example, the structs-config.xml file in our structs, and the hibernate.cfg.xml of hibernate, and so on.
3.XML can act as a small database
XML file can do a small database, is also a good choice, our program may use some often manual configuration of data, if it is not appropriate to read in the database (because this will increase the work of maintaining the database), you can consider directly using XML to do a small database. Reading files directly in this way is obviously faster than reading databases. For example, the XML file is used to save user chat records in msn.
Getting started case: use XML to record a class information.
Yang Guo male 20 Xiao long female 21
We can open it with a browser:
So can our XML be displayed on the web like html? It's OK, it can also be decorated with css, but we don't need it, we just need to use XML to store data.
In this example, if we change the coding of the first line to utf-8 and then open it with a browser, we will report an error. why?
Because the default coding of xml files is ANSI, that is, the code developed by the American National Standards Institute, it has developed different standards according to different countries and regions, so it is GB2312 in China, so we use GB2312 coding will not make an error, and using UTF-8 will report an error.
The solution is to change the XML file to the encoding mode of UTF-8.
4.XML syntax
A XML file is divided into the following sections:
1. Document declaration
two。 element
3. Attribute
4. Annotation
5.CDATA area, special characters
6. Processing instruction (processing instruction)
4.1.XML syntax-document declaration
The XML declaration is placed on the first line of the XML document
The XML declaration consists of the following parts:
Version-documentation conforms to the XML1.0 specification, and we learn 1. 0
Encoding-document character encoding, such as "GB2312" or "UTF-8"
Standalone-whether the document definition is used independently
Standalone= "no" is the default. Yes is used independently, while no is not used independently.
4.2.XML syntax-elements (or tags, nodes)
(1) each XML document must have one and only one root element
The root element is an element that fully includes all other elements in the document
The start tag of the root element should be placed before the start tag of all other elements
The closing tag of the element should be placed after the closing tag of all other elements
(2) the XML element refers to the tags that appear in the XML file. A tag is divided into an opening tag and an ending tag. A tag can be written in the following ways, such as
Contains the tag body:
Www.sohu.com
Not containing the label body:
, abbreviated as:
(3) several sub-tags can also be nested in a tag. However, all tags must be reasonably nested, and cross-nesting is absolutely not allowed, such as
Welcome to www.sohu.com
This kind of situation must be misreported.
(4) for all spaces and line breaks that appear in XML tags, the XML parser will treat them as tag contents. For example, the meaning of the following two paragraphs is different.
Xiaoming
And as follows:
Xiaoming
(5) since spaces and line breaks are treated as raw content in XML, special attention should be paid to writing XML documents.
(6) naming conventions: an XML element can contain letters, numbers, and other visible characters, but must follow the following specifications:
Case sensitive, for example, element P and element p are two different elements
Cannot start with a number or an underscore "_"
Cannot contain spaces within an element
The middle of the name cannot contain a colon (:)
You can use Chinese, but it's not usually used that way.
4.3.XML Syntax-attribute Tom
(1) attribute values are separated by double quotation marks (") or single quotation marks ('). If there are single quotation marks in the attribute values, they are separated by double quotation marks; if there are double quotation marks, they are separated by single quotation marks. What if there are both single quotation marks and double quotation marks in the attribute values? this uses entities (escape characters, similar to spaces in html). XML has five predefined entity characters, as follows:
(2) an element can have multiple attributes, and its basic format is:
(3) A specific attribute name can only appear once in the same element tag.
(4) attribute values cannot include, &, if they must be included, use entities.
4.4.XML Syntax-comment
The comments for XML are similar to those in HTML:
(1) the content of the comments should not appear--
(2) do not put comments in the middle of the tag
(3) comments cannot be nested
(4) comments can be placed anywhere except the mark
4.5.XML syntax-CDATA section
If there is such a requirement, you need to transfer a picture through a XML file, what do you do? In fact, all the files we see on the computer are essentially strings, but they are special binary strings. We can pass the binary string of an image through the XML file, and then parse it into an image. Then the string will contain a large number of special illegal characters such as & or ". At this point, the parsing engine will report an error.
Therefore, some content may not want to be parsed by the parsing engine, but rather treated as raw content, which is used to interpret the entire piece of text as pure character data rather than markup. This is going to use the CDATA festival.
The syntax is as follows:
You can enter any character (except]] > in the CDATA section, but it cannot be nested!
As in the following example, it will not report an error in this case, but it will report an error if it is not included in the cdata section:
Yang Guo-nan 20 4.6.XML Grammar-processing instruction
Processing instruction, referred to as PI (processing instruction). Processing instructions are used to instruct the parsing engine how to parse XML files, as shown in the following example:
For example, we can also use css stylesheets to decorate the XML file, and write my.css as follows:
Name {font-size:80px; font-weight:bold; color:red;} sex {font-size:60px; font-weight:bold; color:blue;} sex {font-size:40px; font-weight:bold; color:green;}
We introduce this css file using processing instructions in the xml file, as follows:
Yang Guo male 20 Xiao long female 21
At this point, when we open the xml file with a browser, we will find that the browser parses a styled view instead of a simple directory tree:
However, XML processing instructions are not required to be mastered, because very few are used.
5. Formal XML documents-Summary
Grammatical norms:
XML declaration statement
two。 There must be a root element
3. Tags are case sensitive
4. Attribute values are in quotation marks
5. Mark in pairs
6. Null tag off
7. Elements are nested correctly
The above is all the contents of the article "what is the use of XML?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.