I have a TCP
network protocoll where the informations/data are sent as xml documents
. Now I would like to match these informations against multiple xsd
files. The data is beeing received randomly, so I would like to know which information is coming by validating them against my xsd files
.
I have already created the xsd files (~25) which should match
In the second step, I would like to create an instance of a customClass
based on the matched xsd
file.
The first part of my question has already been answered on SO. For my second question, I need some help.
1 How to validate a xml against multiple xsd
- already been answered: https://stackoverflow.com/a/11801566/6229375
private void _LoadSchemaSet()
{
_Logger.Debug("Loading schemata..");
var assembly = Assembly.GetExecutingAssembly();
var specs = assembly.GetManifestResourceNames().Where(r => r.ToLower().StartsWith("myCompany.myCustomer.specs") && r.EndsWith(".xsd"));
foreach (string spec in specs)
{
_Logger.Trace(spec);
_SchemaSet.Add(XmlSchema.Read(assembly.GetManifestResourceStream(spec), _Schema_ValidationEventHandler));
}
}
public bool ValidateXDocument(XDocument document)
{
bool result = true;
document.Validate(_SchemaSet, (sender, args) => { result = false; });
// at this point I would like to get the xsd file which matches
return result;
}