简体   繁体   English

XSD 架构未在 basex 中验证

[英]XSD schema not validating in basex

I am tasked with adding type="DeptType" to an xsd file and validating it in basex against an xml document.我的任务是将 type="DeptType" 添加到 xsd 文件并在 basex 中针对 xml 文档对其进行验证。 I have validated both in notepad++ but I get an error in basex when trying to validate.我已经在 notepad++ 中验证了两者,但是在尝试验证时我在 basex 中遇到了错误。

XSD XSD

<?xml version="1.0"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="dept" type="DeptType" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="id" type="xs:string" />
                        </xs:extension>
                     </xs:simpleContent>
                  </xs:complexType>
            </xs:element>
            <xs:element name="staff" type="StaffType" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
    <xs:key name="deptKey">
        <xs:selector xpath="dept"/>
        <xs:field xpath="@id"/>
    </xs:key>
    <xs:key name="staffKey">
        <xs:selector xpath="staff"/>
        <xs:field xpath="@id"/>
    </xs:key>
    <!-- keyref does not work with simpleContent -->
    <xs:keyref name="staffdeptref" refer="deptKey">
        <xs:selector xpath="staff"/>
        <xs:field xpath="@dept"/>
    </xs:keyref>
</xs:element>
<xs:complexType name="StaffType">
    <xs:choice>
        <xs:element name="staff" type="StaffType" maxOccurs="unbounded" />
        <xs:element name="name" type="xs:string"/>
    </xs:choice>
    <xs:attribute name="dept"/>
    <xs:attribute name="id"/>
</xs:complexType>
</xs:schema>

xml xml

<?xml version="1.0" ?>
<root  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
    <dept id="i1"><name>it</name></dept>
    <dept id="i2"><name>law</name></dept>
    <staff id="i2"><name>steve</name></staff>
    <staff id="i3" dept="i2"><name>jerry</name></staff>
</root>

basex validation validate:xsd("doc-4xsd.xml") basex 验证 validate:xsd("doc-4xsd.xml")

The error I get is enter image description here我得到的错误是在此处输入图像描述

I think it's because of this part:我认为这是因为这部分:

<xs:element name="dept" type="DeptType" maxOccurs="unbounded">
    <xs:complexType>

Since the complexType is defined within the element , you shouldn't specify the type attribute.由于complexType是在element中定义的,因此您不应指定type属性。 I think the type attribute is just for referencing types elsewhere in the schema.我认为type属性仅用于在架构中的其他地方引用类型。 So it's either:所以它是:

<xs:element name="dept" maxOccurs="unbounded">
    <xs:complexType>

or或者

<xs:element name="dept" type="DeptType" maxOccurs="unbounded"/>

<xs:complexType name="DeptType">

but not both.但不是两者兼而有之。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM