gpt4 book ai didi

xml - XSD 错误 : References from this schema to components in no namespace are not allowed

转载 作者:行者123 更新时间:2023-12-05 05:18:28 26 4
gpt4 key购买 nike

以下是我的 XML 架构,后面是我要验证的 .xml 文件。

我继续收到错误

Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'type': References from this schema to components in no namespace are not allowed, since not indicated by an import statement.

我是这方面的新手,我对使用命名空间的理解是创建“全局”类型,例如我在全局重用的复杂类型“OneType”。

我的样式表:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="test/namespace" targetNamespace="test/namespace"
elementFormDefault="qualified">
<xsd:complexType name="OneType">
<xsd:annotation>
<xsd:documentation>One Test</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element name="One"/>
</xsd:choice>
</xsd:complexType>

<xsd:element name="testroot">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Test" type="OneType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

我的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<tns:testroot xmlns:tns="test/namespace">
<tns:Test>
<tns:One/>
</tns:Test>
</tns:testroot>

最佳答案

替换

    <xsd:element name="Test" type="OneType"/>

    <xsd:element name="Test" type="tns:OneType"/>

然后您的 XSD 将没有错误,并且您的 XML 将对您的 XSD 有效。

关于xml - XSD 错误 : References from this schema to components in no namespace are not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47893948/

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