当前位置:网站首页>20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
2022-07-04 10:30:00 【Big bear loves to work】
XML Learning notes
1.XML What is it
1.1 brief introduction
- The main function : Realize data transmission between programs 、 The configuration file
config.xml、 Store data as a small database - Canonical data format , The data is structured
1.2 what is XML?
- XML: Extensible markup language
- For transmitting and storing data , Instead of presenting the data
- Labels must be customized
<root>
<user> Dong Xiao D</user>
<age>23</age>
</root>
- XML and HTML The difference between
- HTML The label of cannot be customized 、XML The label can be customized
- HTML The grammar of is not strict 、XML The grammar of is very strict
- HTML Used to show data 、XML For storing and transmitting data
2. Rule of grammar
2.1 Basic grammar
must There are root nodes ( There can only be one ) The following is an error case
<root> <student> Nicola </student> </root> <root1> <student> Zhao si </student> </root1>XML The header statement is optional
<?xml version="1.0" encoding="UTF-8"?>
- be-all XML All elements must It's a pair of labels
- Tag names are case sensitive
- Labels cannot be crossed
- Annotation method
<root>
<user> Dong Xiaodong </user>
<!--<age>23</age>-->
</root>
Special characters require entity escape characters

The name of the label can be the same
Namespace
Situations that cause naming conflicts : Two Different documents Used the same Element name
Avoid naming conflicts by using prefixes
1. Define prefix
Namespaces pass through elements
xmlnsAttribute definitionsxmlns:ns="http://www.dzc.com"Mode one : When using the element with the same name, define the namespace it belongs to
<root> <ns:student xmlns:ns="http://www.dzc.com"> <stu> Dong Xiaodong </stu> </ns:student> notes :ns Is a prefix that represents a namespace student Is the element with the same name <fs:student xmlns:fs="http://www.fzc.com"> <stu> Feng Zhaocheng </stu> </fs:student> </root>Mode two : Declare the namespace definition in the root element
<root xmlns:ns="http://www.dzc.com" xmlns:fs="http://www.fzc.com"> <ns:student> <stu> Dong Xiaodong </stu> </ns:student> notes :ns Is a prefix that represents a namespace student Is the element with the same name <fs:student> <stu> Feng Zhaocheng </stu> </fs:student> </root>
XML With LF Store newlines
2.2 Element attributes
Attributes are just some additional information that describes the tag
<root>
<student>
<user> Dong Xiaodong </user>
<age>23</age>
</student>
<student>
<user age = "23"> Dong</user>
</student>
</root>
- A tag can have multiple properties , Attribute values need to be enclosed in quotation marks
- Basically not much use , Additional parsing code will be added
2.3 Use CDATA The syntax does not parse the specified text
<![CDATA[ Need text content that is not parsed ]]>
for example :
<root>
<student>
<user age = "23"> <![CDATA[a>b,c<d]]></user>
</student>
</root>
- When there are many special characters , Use CDATA grammar
- CDATA Nesting not allowed
2.4 XML Of DTD and XML Schema
- DTD and Schema It's all defined XML Document structure , however XML Schema More commonly used .
3. analysis XML
[C# operation XML Methods, - Solitary summer - Blog Garden (cnblogs.com)]:
[C++ in XML Read and write operations - htj10 - Blog Garden (cnblogs.com)]:
4. In life XML Case study
- XMLX Journalism
<?xml version="1.0" encoding="ISO-8859-1"?>
<nitf>
<head>
<title>Colombia Earthquake</title>
</head>
<body>
<headline>
<hl1>143 Dead in Colombia Earthquake</hl1>
</headline>
<byline>
<bytag>By Jared Kotler, Associated Press Writer</bytag>
</byline>
<dateline>
<location>Bogota, Colombia</location>
<date>Monday January 25 1999 7:28 ET</date>
</dateline>
</body>
</nitf>
summary
1.XML Mainly used for data exchange 、 Sharing and storage
2. Tree structure
3. All modern browsers use XML Parser , For reading and operation XML
4.DOM(Document Object Model) The file object model defines an access XML Standard method of
5.XMLHttpRequest Object provides a function of communicating with the server after the web page is loaded
6.XML Namespaces provide a way to resolve element name conflicts
7.CDATA The text in the area will be XML The parser ignores
边栏推荐
- Exercise 9-1 time conversion (15 points)
- Exercise 7-3 store the numbers in the array in reverse order (20 points)
- Deep learning 500 questions
- 183 sets of free resume templates to help everyone find a good job
- leetcode842. Split the array into Fibonacci sequences
- /*Write a loop to output the elements of the list container in reverse order*/
- /*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
- Write a program that uses pointers to set all elements of an int array to 4.18: 0.
- Doris / Clickhouse / Hudi, a phased summary in June
- The future education examination system cannot answer questions, and there is no response after clicking on the options, and the answers will not be recorded
猜你喜欢

Servlet基本原理与常见API方法的应用

Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2

Collection of practical string functions

leetcode842. Split the array into Fibonacci sequences

Number of relationship models

Rhcsa12
如果不知道這4種緩存模式,敢說懂緩存嗎?

Vs201 solution to failure to open source file HPP (or link library file)

From programmers to large-scale distributed architects, where are you (2)

The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
随机推荐
Basic principle of servlet and application of common API methods
按键精灵跑商学习-商品数量、价格提醒、判断背包
Sword finger offer 31 Stack push in and pop-up sequence
Exercise 9-1 time conversion (15 points)
Occasional pit compiled by idea
对于程序员来说,伤害力度最大的话。。。
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
Lavel document reading notes -how to use @auth and @guest directives in lavel
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 2
BGP ---- border gateway routing protocol ----- basic experiment
Deep learning 500 questions
Service developers publish services based on EDAs
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
Doris / Clickhouse / Hudi, a phased summary in June
Dos:disk operating system, including core startup program and command program
IPv6 comprehensive experiment
leetcode1229. Schedule the meeting
OSPF comprehensive experiment
Seven examples to understand the storage rules of shaped data on each bit
On binary tree (C language)