xml 入门 shema_01

本文介绍了一个具体的 XML Schema 定义示例,展示了如何定义 XML 文档的结构与元素,包括书籍、标题、内容及作者等字段的详细规范。

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>



评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值