[Is there an XML-technology specific newsgroup for .NET on which questions of this nature would be more appropriate? ADVANCED-DOTNET doesn't seem quite right, but I don't see any other DevelopMentor lists that fit the profile.]
I am attempting to parse the XML Schema schema http://www.w3.org/2001/XMLSchema.xsd) using the System.Xml.Schema.XmlSchema.Read(XmlReader, ValidationEventHandler) method. I need to do so in order to access the facets associated with the derived base simple types. Unfortunately, I am constantly receiving a NullReferenceException thrown from the deep, dark innards of the .NET Framework, without so much as a hint of what is going wrong. I've successfully parsed other schemas using the same exact code. The schema does refer to XMLSchema.dtd, so my initial thinking was that it was failing while trying to resolve external entities -- especially since the call raising the exception seems to be within the dtd parsing. The dtd is an embedded resource within my project for which I had to author a custom XmlResolver, but I have traced through my code and it is (seemingly) resolving and returning an open stream correctly. The stack trace along with the majority of the code that I am using is included below. I am hoping that somebody out there has encountered a similar issue and has advice for me. I'm sure it's some foolish oversight on my part -- at least I hope so. The stack trace: NullReferenceException: Object reference not set to an instance of an object. System.Xml.XmlStreamReader.Read(Byte[] data, Int32 offset, Int32 length) +11 System.Xml.XmlScanner..ctor(XmlStreamReader reader, XmlNameTable ntable, Encoding enc) +196 System.Xml.Schema.DtdParser.ParseDocTypeDecl() +827 System.Xml.Schema.DtdParser.Parse() +61 System.Xml.XmlTextReader.ParseDtd(XmlScanner scanner) +71 System.Xml.XmlTextReader.ParseTag() +1379 System.Xml.XmlTextReader.ParseRoot() +234 System.Xml.XmlTextReader.Read() +127 System.Xml.XmlValidatingReader.ReadWithCollectTextToken() +146 System.Xml.XmlValidatingReader.Read() +26 System.Xml.Schema.Parser.StartParsing(XmlReader reader, String targetNamespace, SchemaInfo schemaInfo) +119 System.Xml.Schema.Parser.Parse(XmlReader reader, String targetNamespace, SchemaInfo schemaInfo) +18 System.Xml.Schema.XmlSchema.Read(XmlReader reader, ValidationEventHandler validationEventHandler) +105 And, here is the code that I am using to parse the schema file: public XmlSchema SomeMethod() { XmlTextReader xmlReader = new XmlTextReader( GetType().Assembly.GetManifestResourceStream("DefaultNamespace.XMLSchema.xsd ")); xmlReader.XmlResolver = new XmlEmbeddedResourceResolver(); XmlSchema schema = XmlSchema.Read(xmlReader, new ValidationEventHandler(MySchemaValidationEventHandler)); schema.Compile(MySchemaValidationEventHandler); return schema; } And, for those who care, here is my XmlResolver definition: public class XmlEmbeddedResourceResolver : XmlResolver { private ICredentials credentials; public override ICredentials Credentials { set { this.credentials = value; } } public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) { int slashIndex = absoluteUri.LocalPath.LastIndexOf('\\'); String path = absoluteUri.LocalPath.Substring(slashIndex + 1); return GetType().Assembly.GetManifestResourceStream("DefaultNamespace." + path); } } Any help would be appreciated. Regards, <joe/> =================================== This list is hosted by DevelopMentor� http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com
