Hi,
I'm trying to validate an XML document against an XSD schema and I receive
the following error:
----------
MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException :
Validation error: The element 'http://xmlns.somewhere.com/something:rDetail'
cannot contain text. Expected 'http://xmlns.somewhere.com/something:AList'.
An error occurred at , (1, 533).
----------
There doesn't seem to be much information about this error - could anyone
please help? I've included the schema fragment and sample XML below.
I'm using an XmlValidatingReader to perform the validation.
e.g.
....
XmlValidatingReader vr = new XmlValidatingReader(new
XmlTextReader(message.Stream));
vr.Schemas.Add(this.schemaCache);
vr.ValidationEventHandler += this.validateEventHandler; //<--THIS gets fired
with my error message
vr.ValidationType = ValidationType.Schema;
while (vr.Read())
{
System.Diagnostics.Debug.WriteLine (vr.Name + " " + vr.Value);
} ;
....
Thanks,
Bill
---------------
---- XSD ------
---------------
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema targetNamespace="http://xmlns.somewhere.com/something"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://xmlns.somewhere.com/something"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="SomeStuff">
<xs:complexType>
<xs:sequence>
...
<xs:element name="rDetail" type="RDetail" />
...
</xs:sequence>
</xs:complexType>
</xs:element>
....
<xs:complexType name="RDetail">
<xs:choice maxOccurs="unbounded">
<xs:element name="AList">
<xs:complexType>
<xs:sequence>
<xs:element name="AListItem" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="SomeData" type="xs:string" minOccurs="0" />
</xs:sequence>
<xs:attribute name="id" form="unqualified" type="xs:string" />
<xs:attribute name="anotherAttribute" form="unqualified"
type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
....
</xs:schema>
---------------
---- XML ------
---------------
<?xml version="1.0" encoding="utf-8"?>
<RDetail xmlns="references the above schema">
<AList>
<AListItem id="theID">
<SomeData>1-2-3-4</SomeData>
</AListItem>
<AListItem id="theID">
<SomeData>something</SomeData>
</AListItem>
<AListItem id="theID">
<SomeData>a,b,c</SomeData>
</AListItem>
</AList>
</RDetail>