当前位置:网站首页>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 >
边栏推荐
- 【6.24-7.1】写作社区精彩技术博文回顾
- [live broadcast appointment] database obcp certification comprehensive upgrade open class
- SuperVariMag 超导磁体系统 — SVM 系列
- June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
- B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
- Lumiprobe phosphide hexaethylene phosphide specification
- Huawei cloud experts explain the new features of gaussdb (for MySQL)
- 白盒加密技术浅理解
- Mipi interface, DVP interface and CSI interface of camera [easy to understand]
- C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
猜你喜欢
Learn MySQL from scratch - database and data table operations
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
云服务器ECS夏日省钱秘籍,这次@老用户快来领走
制造业SRM管理系统供应商全方位闭环管理,实现采购寻源与流程高效协同
Lumiprobe cell imaging study PKH26 cell membrane labeling kit
Huawei cloud experts explain the new features of gaussdb (for MySQL)
The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables
【To .NET】C#集合类源码解析
AI training speed breaks Moore's law; Song shuran's team won the RSS 2022 Best Paper Award
随机推荐
Team up to learn! 14 days of Hongmeng equipment development "learning, practicing and testing" practical camp, free of charge!
transform + asm资料
PostgreSQL varchar[] 数组类型操作
Transform + ASM data
[to.Net] C set class source code analysis
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
Taiaisu M source code construction, peak store app premium consignment source code sharing
indexof和includes的区别
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
11. Users, groups, and permissions (1)
Openai video pre training (VPT): action learning based on watching unmarked online videos
Cache problems after app release
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
Superoptimag superconducting magnet system - SOM, Som2 series
Netease games, radical going to sea
Shell array
寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
[live broadcast appointment] database obcp certification comprehensive upgrade open class
Learning notes - steps of JDBC connection database operation