Hi All,
I have an VS.NET 2003 app which will be processing XML files, some of which
will have empty elements (for example, <Item />). I have an XSD file which
should supply default values, but I am not able to read these plugged in
value using an XMLDocument object. The validation is working fine--it's just
not providing any default values.
Has anybody tried this? Am I must be missing something? This is one of
those that "should be simple..."
Here's a simplifed version of the code and XML files:
XmlDocument xmldoc = new XmlDocument();
XmlSchemaCollection myXmlSchema = new XmlSchemaCollection();
myXmlSchema.Add("", new XmlTextReader("test.xsd"));
XmlValidatingReader myReader = new XmlValidatingReader(new
XmlTextReader("test.xml"));
myReader.Schemas.Add(myXmlSchema);
xmldoc.Load(myReader);
Console.WriteLine (xmldoc.SelectSingleNode ("/Data/Item").InnerText);
I would expect this to output 'abc', which is defined in the XSD (see below).
XMLDoc:
<?xml version="1.0"?>
<Data>
<Item />
</Data>
XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Data">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" default="abc"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Many thanks in advance for any assistance.
Randy Williams
ha***********@hotmail.com