当前位置:网站首页>XML syntax, constraints
XML syntax, constraints
2022-07-01 19:25:00 【Gentle ~】
Dom4J analysis XML、Xpath retrieval XML
XML summary
XML Is an extensible markup language (eXtensible Markup Language) Abbreviation , It is a data representation format , Can describe very complex data structures , It is often used to transmit and store data .
<?xml version="1.0" encoding="UTF-8"?>
<data>
<sender> Zhang San </sender>
<receiver> Li Si </receiver>
<src>
<addr> Beijing </addr>
<date>2022-11-11 11:11:11</date>
</src>
<current> wuhan </current>
<dest> Guangzhou </dest>
</data>
XML Characteristics
One is plain text , By default UTF-8 code ; Second, it can be nested ;
XML Usage scenarios of
XML Content is often transmitted over the network as a message , Or use it as a configuration file to store system information ;
XML The grammar of
XML The suffix of the file is :xml;
The first line is the document declaration
<?xml version="1.0" encoding="UTF-8" ?>
version:XML Default version number 、 The attribute must exist
encoding: Ben XML Coding of documents
XML The label of ( Elements ) The rules
XML You can customize the label .
1. The tag consists of a pair of angle brackets and legal identifiers : <name></name>, There must be a root tag , There is one and only one ;
2. Labels must appear in pairs , There is a beginning , There is an end : <name></name>;
3. Special labels can not be paired , But there must be an end tag , Such as :<br/>;
4. Attributes can be defined in tags , Property and tag name are separated by spaces , Property values must be enclosed in quotation marks <student id = “1”></name>;
5. Tags need to be nested properly ;
XML Notes
XML Annotation information can be defined in the file :<!– The comment -->;
XML Escape character
< < Less than
> > Greater than
& & And no.
' ' Single quotation marks
" " quotes
XML There can be CDATA District
<![CDATA[ … Content … ]]>
Strictly speaking , stay XML There are only ”<” and ”&” It's illegal. , The other three are legal , however , It's a good habit to escape them all , You can also use <![CDATA[]]> To include not being xml What the parser parses .
But we need to pay attention :
1. This part can no longer contain ”]]>”;
2. Nesting is not allowed ;
3.]]> This part cannot contain spaces or line breaks ;
Code example
<?xml version="1.0" encoding="UTF-8" ?>
<!-- notes : There can only be one root tag -->
<student>
<name> Daughter King </name>
<sex> Woman </sex>
<hobby> Tang's monk , Chasing Tang Monk </hobby>
<info>
<age>30</age>
<addr> Women's country </addr>
</info>
<sql>
select * from user where age < 18;
select * from user where age < 18 && age > 10
<![CDATA[ select * from user where age < 18 ]]>
</sql>
</student>
XML constraint
What are document constraints
because XML The file can customize the label , Lead to XML Files can be defined at will , The program may have problems when parsing , So it's OK to XML Carry out writing standard restrictions .
Classification of document constraints
1.DTD
2.schema
DTD constraint
To write DTD Constraint document , The suffix must be .dtd, In the need to write XML Import the file DTD Just constrain the document , Then write according to the provisions of the constraint XML The content of the document .
shortcoming
Cannot constrain specific data types .
Code example
data.dtd
<!ELEMENT bookshelf ( book +)>
<!ELEMENT book ( Title , author , The price is )>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT The price is (#PCDATA)>
test.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE bookshelf SYSTEM "data.dtd">
< bookshelf >
< book >
< Title > Master JavaSE To strengthen </ Title >
< author >dlei</ author >
<!-- DTD Constraints cannot constrain data types -->
< The price is > Very expensive </ The price is >
</ book >
< book >
< Title ></ Title >
< author ></ author >
< The price is ></ The price is >
</ book >
< book >
< Title ></ Title >
< author ></ author >
< The price is ></ The price is >
</ book >
</ bookshelf >
schema constraint
schema You can constrain specific data types , Stronger constraints ,schema It's also a xml file , It is also subject to the requirements of other binding documents , So the writing is more rigorous .
schema Use
1. To write schema Constraint document , The suffix must be .xsd;
2. In the need to write XML Import the file schema Constraint document ;
3. Write according to the constraint content XML The label of the document ;
Code example
data.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.itcast.cn" elementFormDefault="qualified" >
<!-- targetNamespace: Declare the address of the constraint document ( Namespace )-->
<element name=' bookshelf '>
<!-- Write child element -->
<complexType>
<!-- maxOccurs='unbounded': There can be any number of sub elements under the bookshelf !-->
<sequence maxOccurs='unbounded'>
<element name=' book '>
<!-- Write child element -->
<complexType>
<sequence>
<element name=' Title ' type='string'/>
<element name=' author ' type='string'/>
<element name=' The price is ' type='double'/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
test.xml
<?xml version="1.0" encoding="UTF-8" ?>
< bookshelf xmlns="http://www.itcast.cn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.itcast.cn data.xsd">
<!-- xmlns="http://www.itcast.cn" Basic position xsi:schemaLocation="http://www.itcast.cn books02.xsd" Specific location -->
< book >
< Title > The Brave Archer and His Mate </ Title >
< author > Jin yong </ author >
< The price is >399.9</ The price is >
</ book >
< book >
< Title > The Brave Archer and His Mate </ Title >
< author > Jin yong </ author >
< The price is >19.5</ The price is >
</ book >
</ bookshelf >
边栏推荐
- 苹果产品在日本全面涨价,iPhone13涨19%
- 物联网平台thingsboard搭建学习记录
- Chaos engineering platform chaosblade box new heavy release
- Netease games, radical going to sea
- Games202 operation 0 - environment building process & solving problems encountered
- 混沌工程平台 ChaosBlade-Box 新版重磅发布
- 数商云:从规划到落地,五矿集团如何快速构建数字化发展新格局?
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- 一次SQL优化,数据库查询速度提升 60 倍
- transform + asm资料
猜你喜欢

有关 M91 快速霍尔测量仪的更多信息

一次SQL优化,数据库查询速度提升 60 倍

Lake Shore—OptiMag 超导磁体系统 — OM 系列
使用环信提供的uni-app Demo,快速实现一对一单聊

Openai video pre training (VPT): action learning based on watching unmarked online videos

线程的并行、并发、生命周期

Cdga | if you are engaged in the communication industry, you should get a data management certificate

Lumiprobe phosphide hexaethylene phosphide specification

Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性

M91 fast hall measuring instrument - better measurement in a shorter time
随机推荐
【直播预约】数据库OBCP认证全面升级公开课
web开发常用的开源框架的开源协议整理
Dlib+Opencv库实现疲劳检测
The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables
B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
How to realize the bottom layer of read-write lock in go question bank 16
More information about M91 fast hall measuring instrument
C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
Dlib+opencv library for fatigue detection
助力数字经济发展,夯实数字人才底座—数字人才大赛在昆成功举办
Example explanation: move graph explorer to jupyterlab
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
Lake shore M91 fast hall measuring instrument
Junit单元测试框架详解
Lumiprobe 活性染料丨吲哚菁绿说明书
[6.24-7.1] review of wonderful technical blog posts in the writing community
Go language self-study series | go language data type
How to use the low code platform of the Internet of things for personal settings?
有关 M91 快速霍尔测量仪的更多信息
案例分享:QinQ基本组网配置