Servergeek
Mickey Williams' weblog


Powered by Blogger Pro™

Friday, June 13, 2003

On the Partial Implementation of XML Schema Support in Framework 1.1


I ran into a bug with XML Schema support in the framework.

Basically, the problem is that XmlValidatingText reader ignores the default element values from schema when reading documents. I see a lot of posts and blog entries from a lot of smart people on XML-centric teams at Microsoft exhorting more widespread leveraging of XML Schema features. Okay, I'm sold, but I want an XML Schema implementation that doesn't force me to know the rich oral history of XML Schema programming with the framework.

The bug is this: given a simple schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
 <xs:element name="Foo">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="n" type="xs:string" default="default"/>
    <xs:element name="s" type="xs:string" minOccurs="0" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

And this XML instance document:

<Foo>
    <n/>
    <s>zaphod</s>
</Foo>

I don't get the expected behavior when reading through a validating reader like so:

using(FileStream stream = new FileStream(@"..\..\foo.xml", FileMode.Open))
{
 XmlValidatingReader reader = new XmlValidatingReader(new
XmlTextReader(stream));
 reader.Schemas.Add(null, @"..\..\foo.xsd");
 reader.ValidationType = ValidationType.Schema;
 XmlDocument doc = new XmlDocument();
 doc.Load(reader);
 //...
}

The node //Foo/n is empty, but the expected behavior is a value of 'default'.

<rant>Frankly, I'd much prefer to find this kind of information during the architecture phase, instead of developing a design using an approved W3 recommendation, creating a test implementation, spending time debugging it, then googling the earth and searching MSDN for the specific error case. Microsoft is more transparent than most companies I deal with, and I love the XML support in the runtime, but this just annoys the hell out of me. Rants regarding the CSS2 support in IE are hereby included by reference</rant>


Home