XML validation with supplied xsd files

dazg

New Member
This is not a specific programming question, but rather a request to know the proper way to do something."The Something": My code executes user-supplied powershell scripts that emit XML as their stdout. This output is supposed to adhere to a schema that we publish and deliver as part of our software's setup routines. We support versions in the output, so the customer's XML will have something like this for a version 2 output at the root of their XML:\[code\]<my_report version="2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mycompany.com/permanent/config-2.0.xsd config-2.0.xsd">\[/code\]The customer output XML may not be valid XML (hence the need for validation before we consume it).My goal is to obtain the version attribute's value and ensure that it matches up with the proper .xsd file name provided, and then use that .xsd file to validate the output XML.Since the output XML may not be valid, I can't rely on something like XElement.Parse() to get the XML into a variable to operate on it. So, I feel my only recourse is to parse the first element (my_report) and use string operations to do the determination.Note: The machines that the code operates on are not guaranteed to have internet access.My base questions: Is this sane thinking? Am I off in the weeds to do something like this? If it is not sane thinking, what would be good alternative(s)?Platform is Windows Server 2008 R2, C# 4.0 Console Application type.
 
Back
Top