论坛首页 入门技术论坛

xml schema keyref 跨文件外键关联

浏览 2205 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-01-05  

stu.xsd
-----------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:cla="http://www.power.com/class" >
<xs:import namespace="http://www.power.com/class" schemaLocation="class.xsd"/>
    <xs:element name="student">
        <xs:complexType>
            <xs:all>
                <xs:element name="stu_id" type="xs:int"/>
                <xs:element name="name" type="xs:string"/>
                <xs:element name="class_id" type="xs:int"/>
            </xs:all>
        </xs:complexType>
        <xs:key name="key_sut">
            <xs:selector xpath=".//stu_id"></xs:selector>
            <xs:field xpath="."></xs:field>
        </xs:key>
        <xs:keyref refer="cla:key_class" name="keyref_class">
            <xs:selector xpath=".//class_id"></xs:selector>
            <xs:field xpath="."></xs:field>
        </xs:keyref>
    </xs:element>
</xs:schema>

 

 

class.xsd
-----------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:cla="http://www.power.com/class" targetNamespace="http://www.power.com/class">
    <xs:element name="class">
        <xs:complexType>
            <xs:all>
                <xs:element name="class_id" type="xs:int"/>
                <xs:element name="class_name" type="xs:string"/>
            </xs:all>
        </xs:complexType>
        <xs:key name="key_class">
            <xs:selector xpath=".//class_id"></xs:selector>
            <xs:field xpath="."></xs:field>
        </xs:key>
    </xs:element>
</xs:schema>

 

错误区域:
-----------------------------------------------------------------------------------------------------

<xs:keyref refer="cla:key_class" name="keyref_class"> 
    <xs:selector xpath=".//class_id"> </xs:selector> 
    <xs:field xpath="."> </xs:field> 
</xs:keyref> 

 

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics