Error: It was detected that X is in namespace Y, but components from this namespace are not referenceable from schema document

Error: It was detected that X is in namespace Y, but components from this namespace are not referenceable from schema document

这 xsd 个元素有什么问题?

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:complexType name="MessageInfoType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="TimeStamp" type="xsd:string" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="GetData">
        <xsd:annotation>
            <xsd:documentation>Send data</xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element minOccurs="1" name="MessageInfo" type="xsd:MessageInfoType" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

获取错误 MessageInfoType 未声明。

错误信息,

src-resolve.4.2: Error resolving component 'xsd:MessageInfoType'. It was detected that 'xsd:MessageInfoType' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document XSD filename. If this is the incorrect namespace, perhaps the prefix of 'xsd:MessageInfoType' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to XSD filename.

在引用组件但未在给定命名空间中找到时发生。

在您的例子中,您通过向 type="xsd:MessageInfoType" 添加不必要的命名空间前缀并在 XSD 根元素上添加不必要的默认命名空间前缀,阻止了对 MessageInfoType 的成功引用。

如何修复:xsd:schema 中删除默认命名空间声明,并从 [=15= 声明中的 type="xsd:MessageInfoType" 中删除命名空间前缀]:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema elementFormDefault="qualified"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:complexType name="MessageInfoType">
    <xsd:sequence>
      <xsd:element name="TimeStamp" type="xsd:string"
                   minOccurs="0" maxOccurs="1" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="GetData">
    <xsd:annotation>
      <xsd:documentation>Send data</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="MessageInfo" type="MessageInfoType"
                     minOccurs="1" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

然后错误信息就会消失。