Re: xsd:string not validly derived

Hi JK,

> I am validating the schema using xerces.The xml I have is
>
> <?xml version='1.0' encoding='UTF-8'?>
> <ns1:getCities
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ns1="http://tempuri.org/forecast.WeatherForecast"
> SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
> <state xsi:type="xsd:string"
> SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">hh</state>
> </ns1:getCities>

First, you might have problems with this because the namespace
associated with the prefix 'xsd' isn't declared anywhere. You should
have a namespace declaration for the XMLSchema namespace:

<?xml version='1.0' encoding='UTF-8'?>
<ns1:getCities
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:ns1="http://tempuri.org/forecast.WeatherForecast"
  SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
<state xsi:type="xsd:string"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">hh</state>
</ns1:getCities>

Second, you can't say that the element state has the type xsd:string
because it doesn't -- xsd:string is a simple type, and elements can
only have a simple type if they have simple content (contain only
text) and don't have any attributes. Your state element has got an
attribute, so it can't have a simple type.

Third, you can only use xsi:type to explicitly declare the type of an
element if the type that you name in xsi:type is derived from the type
that you use to declare the element. To use the xsi:type attribute on
the state element to say that it has the type of xsd:string, the state
element would have to be declared as either xsd:anySimpleType or
xsd:anyType. In your schema, it's declared as being of a complex type
extended from xsd:string.

I'm not sure why you're using xsi:type at all here, since you've
declared that the state's content is a string in the schema, you don't
need to say it again in the instance. Let us know why you want to use
xsi:type here and we'll see if there's another solution that can help.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Friday, 12 July 2002 09:43:21 UTC