当前位置:网站首页>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 >
边栏推荐
- Lumiprobe free radical analysis h2dcfda instructions
- The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
- Clean up system cache and free memory under Linux
- Lake Shore 连续流动低温恒温器传输线
- XML语法、约束
- 华为联机对战服务玩家掉线重连案例总结
- Huawei game failed to initialize init with error code 907135000
- Gameframework eating guide
- 白盒加密技术浅理解
- 宝,运维100+服务器很头疼怎么办?用行云管家!
猜你喜欢

Lake Shore—OptiMag 超导磁体系统 — OM 系列
![[pytorch record] automatic hybrid accuracy training torch cuda. amp](/img/a5/cf1eb2801380cf2887dfd532d3eb1e.jpg)
[pytorch record] automatic hybrid accuracy training torch cuda. amp

Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?

Lake shore M91 fast hall measuring instrument

SuperVariMag 超导磁体系统 — SVM 系列

Viewing technological changes through Huawei Corps (VI): smart highway

Lumiprobe free radical analysis h2dcfda instructions

华为游戏初始化init失败,返回错误码907135000

【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数

苹果产品在日本全面涨价,iPhone13涨19%
随机推荐
Lean thinking: source, pillar, landing. I understand it after reading this article
The difference between indexof and includes
中英说明书丨人可溶性晚期糖基化终末产物受体(sRAGE)Elisa试剂盒
实现一个Prometheus exporter
Shell array
【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
transform + asm资料
kubernetes命令入门(namespaces,pods)
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
Summary of the core steps in the life cycle of beans
M91快速霍尔测量仪—在更短的时间内进行更好的测量
Games202 operation 0 - environment building process & solving problems encountered
【6.24-7.1】写作社区精彩技术博文回顾
机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效
Lake shore optimag superconducting magnet system om series
Specification of lumiprobe reactive dye indocyanine green
Improve yolov5 with gsconv+slim neck to maximize performance!
Example explanation: move graph explorer to jupyterlab
Lake Shore M91快速霍尔测量仪
PostgreSQL varchar[] 数组类型操作