The XSD:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:DataBodyTemperature="Docobo.DataBodyTemperature" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="tDataBodyTemperature">
<xs:sequence>
<xs:element name="Answer" type="xs:double" />
<xs:element minOccurs="0" maxOccurs="1" name="AmbientTemperature" type="xs:double" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="tDataItem">
<xs:choice>
<xs:element name="DataBodyTemperature" type="tDataBodyTemperature" />
</xs:choice>
</xs:complexType>
<xs:element name="DataItem">
<xs:complexType>
<xs:complexContent mixed="false">
<xs:extension base="tDataItem">
<xs:attribute fixed="1" name="SchemaVersion" type="xs:integer" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
The XML:
<DataItem>
<DataBodyTemperature xmlns:DataBodyTemperature="Docobo.DataBodyTemperature">
<DataBodyTemperature:Answer>37.8</DataBodyTemperature:Answer>
<DataBodyTemperature:AmbientTemperature>28.5</DataBodyTemperature:AmbientTemperature>
</DataBodyTemperature >
</DataItem>
I am getting a validation error:
Xml failed schema validation: The element ‘DataBodyTemperature’ has invalid child element ‘Answer’ in namespace ‘Docobo.DataBodyTemperature’. List of possible elements expected: ‘Answer’
Your problem is that your schema doesn’t specify a target namespace – consequently all types are associated with the null namespace.
Your error is caused because the schema specifies that the
DataBodyTemperatureelement (which is in the null namespace) should contain onlyAnswerandAmbientTemperatureelements (both of which are declared in the null namespace), however in your document these elements are in fact in theDocobo.DataBodyTemperaturenamespace, essentially making them completely different elements.A sample of xml conforming to your given schema would be:
Notice that there is no namespace declaration – all elements are in the default namespace. I suspect what you really want however is to modify your xsd so that it specifies a target namespace.
Note that you now also need to qualify the
tDataItemandtDataBodyTemperaturetypes as they are no longer declared in the null namespace.Also note that in your sameple XML the
DataItemandDataBodyTemperatureelements aren’t in the “Docobo.DataBodyTemperature” namespace and so now wouldn’t be validated against the above schema.You may also find it helpeful to get a sample xml document for a schema – you can do this in Visual Studio 2008 or later using the XML Schema Explorer, see How to generate sample XML documents from their DTD or XSD?.