gpt4 book ai didi

元素的 XML/XSD 'extension' 始终具有未定义的复杂类型

转载 作者:数据小太阳 更新时间:2023-10-29 02:09:03 24 4
gpt4 key购买 nike

我正在尝试编写一个扩展在元素中定义的 ComplexType 的 XSD 架构。

我正在尝试使用 Notepad++ XMLTools 插件来解决问题,但我总是收到“无法解析架构文件”。没有错误的描述,所以我一直在使用位于此处的验证器来获取更多详细信息:

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

我从中得到的输出是:

状态:未定义的复杂类型“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>

最佳答案

问题是您正在尝试将基本类型值设置为元素。但是“类型”是预期的。你应该让它更像这样:

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

关于元素的 XML/XSD 'extension' 始终具有未定义的复杂类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10112128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com