OK, one last thing related to this problem. The entities now resolve correctly, but the XmlSchema.Compile(...) method is now throwing an Exception "Restriction of anySimpleType is not allowed." As such, I can read the schema into memory, but none of the SOM objects are available to me sans compilation.
Is there a known workaround for this or just an inherent limitation in the framework? Googling for the exact error message turns up exactly 0 results -- which is somewhat discouraging... Thanks. <joe/> -----Original Message----- From: Duffy, JohnJ (IT Westboro) [mailto:[EMAIL PROTECTED] Sent: Monday, September 15, 2003 3:19 PM To: [EMAIL PROTECTED] As suspected, my problem was indeed caused by a foolish oversight. After investigating further, my custom resolver was returning an empty stream when passed "-//W3C//DTD XMLSCHEMA 200102//EN" (within XMLSchema.xsd). I changed my resolver to forward back to the XmlUrlResolver if unable to locate an embedded resource matching the name of the requested information. My new custom XmlResolver: public class XmlEmbeddedResourceResolver : XmlResolver { private XmlResolver fallbackResolver = new XmlUrlResolver(); 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 resourcePath = absoluteUri.LocalPath.Substring(slashIndex + 1); Object resourceStream = GetType().Assembly.GetManifestResourceStream( "DefaultNamespace." + resourcePath); if (resourceStream == null) resourceStream = fallbackResolver.GetEntity( absoluteUri, role, ofObjectToReturn); return resourceStream; } } Apologies for the mundane-ness of my posting. Regards, <joe/> -----Original Message----- From: Joe Duffy [mailto:[EMAIL PROTECTED] Sent: Monday, September 15, 2003 1:37 PM To: [EMAIL PROTECTED] [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(r) 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 =================================== This list is hosted by DevelopMentor(r) 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 =================================== 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
