当前位置:网站首页>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 >
边栏推荐
- 线程的并行、并发、生命周期
- 制造业SRM管理系统供应商全方位闭环管理,实现采购寻源与流程高效协同
- pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
- 宝,运维100+服务器很头疼怎么办?用行云管家!
- 混沌工程平台 ChaosBlade-Box 新版重磅发布
- 云服务器ECS夏日省钱秘籍,这次@老用户快来领走
- 【快应用】Win7系统使用华为IDE无法运行和调试项目
- 从零开始学 MySQL —数据库和数据表操作
- 水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
- 白盒加密技术浅理解
猜你喜欢
从零开始学 MySQL —数据库和数据表操作
Superoptimag superconducting magnet system - SOM, Som2 series
生鲜行业B2B电商平台解决方案,提高企业交易流程标准化和透明度
Games202 operation 0 - environment building process & solving problems encountered
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
ECS summer money saving secret, this time @ old users come and take it away
白盒加密技术浅理解
SuperOptiMag 超导磁体系统 — SOM、SOM2 系列
C端梦难做,科大讯飞靠什么撑起10亿用户目标?
市值蒸发740亿,这位大佬转身杀入预制菜
随机推荐
Lake Shore continuous flow cryostat transmission line
Clean up system cache and free memory under Linux
物联网平台thingsboard搭建学习记录
智慧防疫系统为建筑工地复工复产提供安全保障
Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit
Go语言高级
Learning notes - steps of JDBC connection database operation
Today, with the popularity of micro services, how does service mesh exist?
Lumiprobe free radical analysis h2dcfda instructions
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
How to realize the bottom layer of read-write lock in go question bank 16
Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
Games202 operation 0 - environment building process & solving problems encountered
VBA simple macro programming of Excel
Lumiprobe 活性染料丨吲哚菁绿说明书
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
C端梦难做,科大讯飞靠什么撑起10亿用户目标?
Lake Shore低温恒温器的氦气传输线
Junit单元测试框架详解