Click here to Skip to main content
15,868,042 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a class library in which all the schema are added.
The xsd schema have relative schemas (import/include).
The dll of this project is referenced in another application where I need to validate the input XML, using these referenced dll schema.

Please help me, how can I validate the xml using the referenced dll schema.

I am trying to implement this solution to Biztalk pipeline.

What I have tried:

C#
// Create an XmlReaderSettings object and load the schema into it.
// This will also load in any imported/included schemas.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.Schemas.Add(null, reader);

// Setup the event handler to handle errors/warnings
settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler);

// Get the list of all targetNamespaces from the loaded schemas
List<string> namespaces = new List<string>();
foreach (XmlSchema s in settings.Schemas.Schemas())
{
	if (!string.IsNullOrEmpty(s.TargetNamespace))
	{
		namespaces.Add(s.TargetNamespace);
	}
}

// Load the current Xml Document into a stream
MemoryStream stream = new MemoryStream();
instanceDoc.Save(stream);
stream.Position = 0L;

// Create the validating reader
XmlReader vr = XmlReader.Create(stream, settings);

// Read the document stream - this will validate as it reads
while (vr.Read()) { }
Posted
Updated 21-Feb-16 22:59pm
v3
Comments
Kornfeld Eliyahu Peter 22-Feb-16 6:09am    
Are you saying that your XSDs are embedded into a DLL?
Good news: there is n problem to load those XSD strings into memory and use them for validation...
Bad news: import/include will not work that way...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900