HighTechTalks DotNet Forums  

XSD Validation error: "The element 'x...' cannot contain text

Dotnet XML microsoft.public.dotnet.xml


Discuss XSD Validation error: "The element 'x...' cannot contain text in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
BillAtWork
 
Posts: n/a

Default XSD Validation error: "The element 'x...' cannot contain text - 06-19-2006 , 03:19 AM






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>

Reply With Quote
  #2  
Old   
Zafar Abbas
 
Posts: n/a

Default Re: XSD Validation error: "The element 'x...' cannot contain text - 06-19-2006 , 12:36 PM






Since the content of RDetali is element only , it neither allows text or any
significant whitespaces. Please make sure you do not have any whitespaces in
the content of the RDetail. I stripped your data of whitespaces, and could
validate without problems.

Zafar

"BillAtWork" <BillAtWork (AT) nospam (DOT) nospam> wrote

Quote:
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.