加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

元素的XML / XSD“扩展”始终具有未定义的complexType

发布时间:2020-12-16 22:51:17 所属栏目:百科 来源:网络整理
导读:我正在尝试编写一个XSD Schema,它扩展了Element中定义的ComplexType. 我试图使用Notepad XMLTools插件来解决问题,但我总是得到“无法解析架构文件”.没有错误的描述,所以我一直在使用这里的Validator来获取更多细节: http://www.xmlforasp.net/schemavalida
我正在尝试编写一个XSD Schema,它扩展了Element中定义的ComplexType.

我试图使用Notepad XMLTools插件来解决问题,但我总是得到“无法解析架构文件”.没有错误的描述,所以我一直在使用这里的Validator来获取更多细节:

http://www.xmlforasp.net/schemavalidator.aspx

我得到的输出是:

状态:
未定义的complexType’http://test.org:BaseClass’用作复杂类型扩展的基础.

我已经尝试在xs:schema标签中删除:test命名空间,我尝试从ClassHierarchy中的ref中删除test:namespace限定符,并且我尝试将命名空间添加到元素定义中,但是我无法获得模式传递验证.

任何帮助将不胜感激!谢谢

<?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>

解决方法

问题是你正在尝试将基本类型值设置为元素.但预计“类型”.你应该更像这样:

<xs:element name="BaseClass" type="BaseType" />

<xs:complexType name="BaseType">
      ...
</xs:complexType>

<xs:complexType name="SubType">
   <xs:complexContent>
       <xs:extension base="BaseType">
           ....
       </xs:complexContent>
</xs:complexType>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读