[Mono-list] XmlSchemaSet Problem
Kent Boogaart
kentcb at internode.on.net
Tue Feb 7 01:51:49 EST 2006
Hi all,
I've come across a problem with the XmlSchemaSet that presents itself on
mono, but not on MS .NET. Essentially, adding multiple schemas to the set
does not permit them to "see eachother" without imports / includes. I
believe this is a bug in mono, since the documentation for XmlSchemaSet
states:
"Compiled schemas generate a single logical schema, a set of schemas. Any
imported schemas within a schema that are added to the set are directly
added to the set themselves. This means that all types are available to all
schemas."
Here is a simple repro for the problem. Works fine on MS.NET but yields an
error on mono:
--------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
namespace SchemaRepro
{
class Program
{
private const string schema1 = @"<?xml version=""1.0""
encoding=""utf-8"" ?>
<xsd:schema id=""Base.Schema"" elementFormDefault=""qualified""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<xsd:complexType name=""itemBase"" abstract=""true"">
<xsd:attribute name=""id"" type=""xsd:string""
use=""required""/>
<xsd:attribute name=""type"" type=""xsd:string""
use=""required""/>
</xsd:complexType>
</xsd:schema>
";
private const string schema2 = @"<?xml version=""1.0""
encoding=""utf-8"" ?>
<xsd:schema id=""Sub.Schema"" elementFormDefault=""qualified""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<xsd:complexType name=""item"">
<xsd:complexContent>
<xsd:extension base=""itemBase"">
<xsd:attribute name=""itemName""
type=""xsd:string"" use=""required""/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
";
static void Main(string[] args)
{
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(XmlSchema.Read(new
StringReader(schema1), null));
schemas.Add(XmlSchema.Read(new
StringReader(schema2), null));
schemas.ValidationEventHandler +=
schemas_ValidationEventHandler;
schemas.Compile();
Console.WriteLine();
Console.WriteLine("Press any key");
Console.ReadKey();
}
static void schemas_ValidationEventHandler(object sender,
ValidationEventArgs e)
{
Console.WriteLine("Message: {0}", e.Message);
Console.WriteLine("Severity: {0}", e.Severity);
Console.WriteLine("Stack Trace: {0}",
e.Exception.StackTrace);
}
}
}
--------------------------------------------------
As you can see, schema2 attempts to extend a type defined in schema1 but is
unable to see that type when running on mono.
Thanks for any help,
Kent
More information about the Mono-list
mailing list