views:

716

answers:

1

I've got an XML response from another system, but no XSD, so I used the Create Schema option to generate one.

I then added the XSD to my BizTalk 2006 R2 project and set its "Input Instance Filename" property to the original XML message.

Tried the "Validate Instance" option and it FAILS ???, with a couple of errors like so ...
error BEC2004: The xsi:type attribute value 'http://www.w3.org/2001/XMLSchema:int' is not valid for the element 'http://www.aniteps.com/xml/schemas/awm/images4:NumberOfErrors', either because it is not a type validly derived from the type in the schema, or because it has xsi:type derivation blocked.

How the heck can the XML fail that was used to generate the XSD ?

The XML example I have is ...

<?xml version="1.0" encoding="utf-8"?>
<ImportIndexDocumentResponse 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://www.aniteps.com/xml/schemas/awm/images4"&gt;
  <HasErrors>false</HasErrors>
  <NumberOfErrors xsi:type="xsd:int">0</NumberOfErrors>
  <ErrorDescription xsi:type="xsd:string">No exception ocurred.</ErrorDescription>
  <ErrorNumber xsi:type="xsd:int">0</ErrorNumber>
  <FailedItems>
    <Item>
      <OriginalDataString xsi:type="xsd:string" />
      <ErrorDescription xsi:type="xsd:string" />
    </Item>
  </FailedItems>
  <UniqueDocumentReferences>
    <UniqueDocumentReference>FA40FE</UniqueDocumentReference>
    <UniqueDocumentReference>U55922</UniqueDocumentReference>
  </UniqueDocumentReferences>
</ImportIndexDocumentResponse>

And BizTalk / Visual Studio 2005 generates ...

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            attributeFormDefault="unqualified" 
            elementFormDefault="qualified" 
            targetNamespace="http://www.aniteps.com/xml/schemas/awm/images4"&gt;
  <xs:element name="ImportIndexDocumentResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="HasErrors" type="xs:boolean" />
        <xs:element name="NumberOfErrors" type="xs:unsignedByte" />
        <xs:element name="ErrorDescription" type="xs:string" />
        <xs:element name="ErrorNumber" type="xs:unsignedByte" />
        <xs:element name="FailedItems">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Item">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="OriginalDataString" />
                    <xs:element name="ErrorDescription" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="UniqueDocumentReferences">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="UniqueDocumentReference" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xsd:schema>
+3  A: 

The XSD generator is reasonably dumb, and didn't notice that the sample instance document contained type annotations (xsi:type attributes). So it decided that <ErrorDescription> should contain unsigned bytes and not signed integers, as the type annotation said.

What happens then is that the validator becomes confused because there are two distinct type definitions for the element, so who should it believe? You could try changing the schema so that the type definitions match the xsi:type overrides, that may help a bit.

tomasr
Spot on Tomas, changed to xs:int and my unit test works a treat.Many thanks for the help
SteveC