我正在尝试编写一个扩展元素中定义的 ComplexType 的 XSD 架构。
我正在尝试使用 Notepad++ XMLTools 插件来解决问题,但我总是得到“无法解析架构文件”。没有错误的描述,所以我一直在使用位于此处的验证器来获取更多详细信息:
http://www.xmlforasp.net/schemavalidator.aspx
我从中得到的输出是:
状态: 未定义的 complexType 'http://test.org:BaseClass' 用作复杂类型扩展的基础。
我尝试在 xs:schema 标记中删除 :test 命名空间,我尝试从 ClassHierarchy 中的 ref 中删除 test: 命名空间限定符,并且我尝试将命名空间添加到元素定义中,但我无法获得架构以通过验证。
任何帮助将不胜感激!谢谢
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
    xmlns:test="http://test.org"
    targetNamespace="http://test.org"
    elementFormDefault="qualified"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="BaseClass">
        <xs:complexType>
            <!-- More referneces in here (Meaning this must be a complex type) but removed out to make a bit simpler -->
            <xs:attribute name="test_name" type="xs:string" use="required"/>
            <xs:attribute name="second_name" type="xs:string"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="SubClass">
        <xs:complexType>
            <xs:complexContent>
                <xs:extension base="test:BaseClass">
                    <xs:attribute name="min_value" type="xs:float" default="0.0"/>
                    <xs:attribute name="max_value" type="xs:float" default="1.0"/>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="ClassHierarchy">
        <xs:complexType>
            <xs:sequence>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element ref="test:BaseClass" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element ref="test:SubClass" minOccurs="0" maxOccurs="unbounded"/>
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
XML 文件包含:
<?xml version="1.0"?>
    <ClassHierarchy
    xmlns="http://test.org"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://test.org Test.xsd">
        <BaseClass test_name="Test1" />
        <SubClass test_name="Test2" min_value="0.0" max_value="1.0" />
    </ClassHierarchy>