Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2007

Tip: Looking for answers? Try searching our database.

XmlSchemaException on XmlSchemaSet.Compile() with imported schema

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
iHadMyPersonalInfoIndexed@gmail.com - 28 Jun 2007 20:38 GMT
I'm absolutely tearing my hair out on this one, and would appreciate
any help anyone can provide. I need to validate incoming XML files
against a local XSD which imports a remote XSD. When setting up the
XmlReaderSettings, I am getting a XmlSchemaException on
XmlSchemaSet.Compile(). I have stripped down my setup to the very
basics below.

(1) REMOTE XSD FILE: Available at http://localhost/ImportedSchema.xsd

<?xml version="1.0" encoding="utf-8"?>
<s:schema id="ImportedSchema" targetNamespace="urn:schemas-me-
com:Test" elementFormDefault="qualified" xmlns="urn:schemas-me-
com:Test" xmlns:tns="urn:schemas-me-com:Test" xmlns:s="http://
www.w3.org/2001/XMLSchema">
 <s:complexType name="TestType">
   <s:sequence>
     <s:element minOccurs="1" maxOccurs="1" name="SomeValue"
type="s:string" />
   </s:sequence>
 </s:complexType>
</s:schema>

(2) LOCAL XSD FILE: Available in output directory

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="LocalSchema" targetNamespace="urn:schemas-me-
com:TestLocal" elementFormDefault="qualified" xmlns="urn:schemas-me-
com:TestLocal" xmlns:mstns="urn:schemas-me-com:TestLocal"
xmlns:imp="urn:schemas-me-com:Test" xmlns:xs="http://www.w3.org/2001/
XMLSchema">
 <xs:import id="imp" namespace="urn:schemas-me-com:Test"
schemaLocation="http://localhost/ImportedSchema.xsd" />
 <xs:element name="LocalStuff">
   <xs:complexType>
     <xs:sequence>
       <xs:element name="LocalElement" type="xs:string" maxOccurs="1"
minOccurs="1" />
       <xs:element name="ImportedElement" type="imp:TestType"
maxOccurs="1" minOccurs="1" />
     </xs:sequence>
   </xs:complexType>
 </xs:element>
</xs:schema>

(3) CODE trying setup the XmlReaderSettings

XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, "LocalSchema.xsd");
schemaSet.Compile(); // BANG! XmlSchemaException thrown!
// ... etc ...

What is really strange is that Visual Studio is resolving everything
perfectly within the IDE. if I set up a test XML file, I'm getting
intellisense on the imported types and everything. Here's a test XML
file that is working fine:

<?xml version="1.0" encoding="utf-8" ?>
<LocalStuff
 xmlns="urn:schemas-me-com:TestLocal"
 xmlns:imp="urn:schemas-me-com:Test">
 <LocalElement>Hello</LocalElement>
 <ImportedElement>
   <imp:SomeValue>World</imp:SomeValue>
 </ImportedElement>
</LocalStuff>

Any ideas?

Dave
iHadMyPersonalInfoIndexed@gmail.com - 28 Jun 2007 21:41 GMT
Solved the problem. My localhost was using Integrated Windows
Authentication. I had to specify the credentials for the XmlResolver:

XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;
schemaSet.XmlResolver = resolver;

Hope it helps someone else!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.