D
Dan
Hi, I'm creating a C# assembly which loads from its resources some XSDL
schemas and use them to validate external XML files. Some of these schemas
refer to other schemas via include commands. How can I let the validator
resolve these references in schemas loaded from assembly resources? I think
I should use an XmlUrlResolver, but I do not know how it works.
Here's an attempt with this code snippet, let's say that the 2 schemas are
named A.xsd and B.xsd, both placed as embedded resources in the Dummy
assembly: should I add both to a schema collection, and/or use a resolver
(how?), or what? Could anyone give a hint? Thx guys!
// create 2 streams for 2 schemas from this assembly resource
Assembly a = Assembly.GetExecutingAssembly();
Stream stA = a.GetManifestResourceStream("Dummy.A.xsd");
Stream stB = a.GetManifestResourceStream("Dummy.B.xsd");
// create a resolver?
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential nc;
nc = new System.Net.NetworkCredential(... what to do here...?);
resolver.Credentials = nc;
// create a schema collection?
XmlSchemaCollection xsc = new XmlSchemaCollection();
XmlTextReader rdA = new XmlTextReader(new StreamReader(stA,
System.Text.Encoding.UTF8));
xsc.Add(null, rdA, resolver);
XmlTextReader rdB = new XmlTextReader(new StreamReader(stB,
System.Text.Encoding.UTF8));
xsc.Add(null, rdB, resolver);
// ... validate with a XmlValidatingReader using xsc ...
schemas and use them to validate external XML files. Some of these schemas
refer to other schemas via include commands. How can I let the validator
resolve these references in schemas loaded from assembly resources? I think
I should use an XmlUrlResolver, but I do not know how it works.
Here's an attempt with this code snippet, let's say that the 2 schemas are
named A.xsd and B.xsd, both placed as embedded resources in the Dummy
assembly: should I add both to a schema collection, and/or use a resolver
(how?), or what? Could anyone give a hint? Thx guys!
// create 2 streams for 2 schemas from this assembly resource
Assembly a = Assembly.GetExecutingAssembly();
Stream stA = a.GetManifestResourceStream("Dummy.A.xsd");
Stream stB = a.GetManifestResourceStream("Dummy.B.xsd");
// create a resolver?
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential nc;
nc = new System.Net.NetworkCredential(... what to do here...?);
resolver.Credentials = nc;
// create a schema collection?
XmlSchemaCollection xsc = new XmlSchemaCollection();
XmlTextReader rdA = new XmlTextReader(new StreamReader(stA,
System.Text.Encoding.UTF8));
xsc.Add(null, rdA, resolver);
XmlTextReader rdB = new XmlTextReader(new StreamReader(stB,
System.Text.Encoding.UTF8));
xsc.Add(null, rdB, resolver);
// ... validate with a XmlValidatingReader using xsc ...