xml 入门 shema_01

本文通过一个具体的XML Schema实例,展示了如何定义书籍元素的结构,包括书名、内容、作者等属性,并详细说明了如何使用choice、sequence等元素以及attribute定义必填字段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

shema基础:



shema的使用:



shema的属性和语法:



相应的源码:

1.shema的格式:

<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/02" xmlns:tns="http://www.example.org/02" elementFormDefault="qualified"> <element name="books"> <complexType> <sequence maxOccurs="unbounded"> <element name="book"> <complexType> <sequence> <element name="title" type="string"></element> <element name="content" type="string"></element> <choice> <element name="author" type="string"></element> <element name="authors"> <complexType> <sequence maxOccurs="3"> <element name="author" type="string"></element> </sequence> </complexType> </element> </choice> </sequence> <attribute name="id" type="int" use="required"/> </complexType> </element> </sequence> </complexType> </element> </schema>
2.shema控制的xml文件

<?xml version="1.0" encoding="UTF-8"?> <books xmlns="http://www.example.org/02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/02"> <book id="1"> <title>think in java</title> <content>hello java world</content> <author>zizhu</author> </book> <book id="2"> <title>think in java (4 edition)</title> <content>base java</content> <authors> <author>bruce</author> <author>mike</author> </authors> </book> </books>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值