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

泄露秘密 提交于 2021-01-27 22:02:02

问题


What's wrong in this xsd elements?

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

Getting error MessageInfoType is not declared.


回答1:


The error message,

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.

occurs when a component is referenced but not found in the given namespace.

In your case, you've prevented successful referencing of the MessageInfoType by adding an unnecessary namespace prefix to type="xsd:MessageInfoType" and an unnecessary default namespace prefix on the XSD root element.

How to fix: Remove the default namespace declaration from xsd:schema, and remove the namespace prefix from type="xsd:MessageInfoType" on the declaration of MessageInfo:

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

Then the error message will go away.



来源:https://stackoverflow.com/questions/43288137/error-it-was-detected-that-x-is-in-namespace-y-but-components-from-this-namesp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!