2

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Nitin Aggarwal
  • 451
  • 1
  • 7
  • 18

1 Answers1

4

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240