xml Schema import

first_.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     targetNamespace="www.first.com">
    <xs:simpleType name="bid">
        <xs:restriction base="xs:string">
            <xs:pattern value="[A]\d{6}"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
second_.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="www.second.com">
    <xs:simpleType name="aid">
        <xs:restriction base="xs:string">
            <xs:pattern value="[c]\d{6}"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
_third.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="www.myweb.com"
    targetNamespace="www.myweb.com"
    xmlns:first="www.first.com"
    xmlns:second="www.second.com">
    
    <xs:import namespace="www.first.com" schemaLocation="first_.xsd"/>
    <xs:import namespace="www.second.com" schemaLocation="second_.xsd"/>
    
    <xs:element name="books" type="infotype"/>
    
    <xs:complexType name="infotype">
        <xs:sequence>
            <xs:element name="book" type="booktype"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="booktype">
        <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="author" type="atype"/>
        </xs:sequence>
        <xs:attribute name="bookid" type="first:bid"/>
    </xs:complexType>
    <xs:complexType name="atype">
        <xs:sequence>
            <xs:element name="firstname" type="xs:string"/>
            <xs:element name="lastname" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="authorid" type="second:aid"/>
    </xs:complexType>
</xs:schema>

说明:

first_.xsd:定义简单类型, 并指定目标命名空间为"www.first.com";

second_.xsd:定义简单类型, 并指定目标命名空间为"www.second.com";

third_.xsd:定义复杂类型,并引用first_.xsd, second_.xsd,引用这两个schema文件,但是目标命名空间不一致。因为third_.xsd引用了first_.xsd, second_.xsd所以必须指定这两个文件的命名空间为"www.first.com"和"www.second.com",否则无法引用firtst.xsd, second.xsd中定义的简单类型数据;

目标命名空间:指定被此Schema文档约束的元素及数据类型都来自于的命名空间;

默认命名空间:指定当前XML文档中使用的元素及数据类型都来自于的命名空间;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值