Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : .Net XmlValidatingReader should fail on complextypes with whitespace?


Larry
6/4/2004 8:00:32 AM
I believe the .Net XmlValidatingReader should fail when validating XML
that contains a ComplexType element with white space when the
ComplexType element has the mixed attribute set to false in the XSD used
for validation.

XSD fragment:

<xs:element name="TRSellerBuyerData">
<xs:complexType mixed="false">
<xs:sequence>
<xs:element ref="BuyerSellerReferrorFlag" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

XML fragment:

<TRSellerBuyerData>
</TRSellerBuyerData>

XML Spy will catch the valdation error and report: "Text not allowed
inside element 'TRSellerBuyerData'

But the following code does not catch the validation error. Is this a
bug in XmlValidatingReader - or am I missing code to catch this? I
assume by XSD is correct since XmlSpy catches the error.


XmlTextReader textReader = new XmlTextReader(reader);

textReader.WhitespaceHandling = WhitespaceHandling.All; //this is the
default

textReader.Normalization = false; //this is the default

XmlValidatingReader validatingReader = new XmlValidatingReader(textReader);

validatingReader.ValidationType = ValidationType.Schema;

validatingReader.Schemas.Add(schemaCollection);

try
{
while(validatingReader.Read());
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}


Priya Lakshminarayanan [MSFT]
6/4/2004 2:18:02 PM
The following complexType's ContentType is ElementOnly according to
structures spec. (http://www.w3.org/TR/xmlschema-1)
and if the ContentType is ElementOnly, then whitespace characters are
allowed according to clause 2.3 of the following rule in the spec:
3.4.4 Complex Type Definition Validation Rules
Validation Rule: Element Locally Valid (Complex Type)
2.3 If the {content type} is element-only, then the element information item
has no character information item [children] other than those whose
[character code] is defined as a white space in [XML 1.0 (Second Edition)].

Thanks,
Priya


[quoted text, click to view]

Larry
6/4/2004 4:14:43 PM
Thank you Priya, how would I change my XSD so that only child elements
are allowed and no "significant" white space?

[quoted text, click to view]
AddThis Social Bookmark Button