微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 xsd 创建主键以及如何使用他

如何解决如何使用 xsd 创建主键以及如何使用他

我想知道如何创建主键并在此处使用它是我的 xsd 代码您可以注意到我创建了两个主键和一个引用键

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <!-- car primary key -->
            <xsd:key name="carKey">
                <xsd:selector xpath="car"/>
                <xsd:field xpath="codeV"/>
            </xsd:key>
    <!-- person primary key -->
            <xsd:key name="personKey">
                <xsd:selector xpath="person"/>
                <xsd:field xpath="codeP"/>
            </xsd:key>
     <!--  personne referential key -->
              <xsd:keyref name="codeOwner" refer="carKey">
                <xsd:selector xpath="car"/>
                <xsd:field xpath="codeP"/>
            </xsd:keyref>
    <xsd:element name="Parking">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="car" />
                <xsd:element name="person" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    
    <xsd:complexType name="car">
        <xsd:sequence>
            <xsd:element name="codeV" ref="car"/>
            <xsd:element name="model" type="xsd:string"/>
            <xsd:element name="mark" type="xsd:string"/>
            <xsd:element name="owner" ref="person"/>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="person">
        <xsd:sequence>
            <xsd:element name="codeP" ref="person"/>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="address" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

我想建一个有几辆车的停车场,每辆车都有一个主人 为此,我们必须使用引用约束

我的xml代码

<?xml version="1.0"?>
<Parking xmlns="http://www.w3schools.com" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="park.xsd"> 
    <car>
        <codeV> number </codeV>
        <mark> Toyota </mark>
        <model> corolla</model>
        <owner> fichale</owner>
    </car>
    <person>
        <codeP> fichale</codeP>
        <name> KEZIRE </name>
        <address> ESP </address>
    </person>
</Parking>

当我尝试运行我的代码时出现此错误

S4s-elt-invalid-content.1:“模式”的内容无效。元素“key”无效、错位或出现频率过高。

我不知道为什么。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。