How to validate an XML doc stored in a string using an XSD stored as an Embedded Resource? (C# 4.0

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I need to validate XML documents against an XSD file thats stored as an embedded resource in my project (C# 4.0 VS2010)
I know can load the XSD file into a StreamReader and then into a string using...
Assembly assembly = Assembly.GetExecutingAssembly();<br/>
var schemaStreamReader = new StreamReader(assembly.GetManifestResourceStream("mySchema.xsd"));<br/>
var schemaString = schemaStreamReader.ReadToEnd();
I assumed I could then do something like...
var schema = new XmlSchema();<br/>
schema.Read( schemaStreamReader or schemaString, ... );
But Read wont accept either.
So how can I "wire-up" the output from loading the resource to the XSD validation?

All the steps Ive shown are changeable, except for the givens:
1) I must start with an XSD stored as an embedded resource
2) use that XSD to validate an XML doc that arrives as a string.
Thanks!
DadCat






View the full article
 
Back
Top