当前位置:网站首页>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 >
边栏推荐
- The intelligent epidemic prevention system provides safety guarantee for the resumption of work and production at the construction site
- 机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效
- 线程的并行、并发、生命周期
- Today, with the popularity of micro services, how does service mesh exist?
- Helium transmission line of lake shore cryostat
- 前4A高管搞代运营,拿下一个IPO
- The difference between indexof and includes
- 【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
- ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
- Love business in Little Red Book
猜你喜欢

【To .NET】C#集合类源码解析

CDGA|从事通信行业,那你应该考个数据管理证书

Lake Shore 连续流动低温恒温器传输线

MATLAB中subplot函数的使用

3. "Create your own NFT collections and publish a Web3 application to show them" cast NFT locally

Example explanation: move graph explorer to jupyterlab

论文阅读【Learning to Discretely Compose Reasoning Module Networks for Video Captioning】

Once the SQL is optimized, the database query speed is increased by 60 times

云服务器ECS夏日省钱秘籍,这次@老用户快来领走

论文阅读【Discriminative Latent Semantic Graph for Video Captioning】
随机推荐
学习笔记【gumbel softmax】
M91快速霍尔测量仪—在更短的时间内进行更好的测量
数商云:从规划到落地,五矿集团如何快速构建数字化发展新格局?
Lake Shore—OptiMag 超导磁体系统 — OM 系列
线程的并行、并发、生命周期
Summary of cases of players' disconnection and reconnection in Huawei online battle service
Dom4J解析XML、Xpath检索XML
Junit单元测试框架详解
[6.24-7.1] review of wonderful technical blog posts in the writing community
Lumiprobe free radical analysis h2dcfda instructions
Contos 7 搭建sftp之创建用户、用户组以及删除用户
Lake Shore 连续流动低温恒温器传输线
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
indexof和includes的区别
Lean thinking: source, pillar, landing. I understand it after reading this article
Lake shore optimag superconducting magnet system om series
[quick application] win7 system cannot run and debug projects using Huawei ide
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
【To .NET】C#集合类源码解析
Getting started with kubernetes command (namespaces, pods)