-1

so time ago i need validate the structure and data simple to send one service. the Web Service receive one structure xml, but this is assincronico to return structure problems.

So I lot a lot of hours in check visually file to file, So i think the idea to check automatic the xml estruct with one XSD, the XSD was provided by the other company.

VhsPiceros
  • 410
  • 1
  • 8
  • 17

1 Answers1

0

I create and used this simple code to create one console program and valid all xml in my test process

class Program {
    static void Main(string[] args) {
        Console.WriteLine("validando input.xml con input.xsd");
        var schemas = new XmlSchemaSet();
        schemas.Add("", "input.xsd");
        Console.WriteLine("Validando...");
        var custOrdDoc = XDocument.Load("input.xml");
        var errors = false;
        custOrdDoc.Validate(schemas, (o, e) => {
                                 Console.WriteLine("{0}", e.Message);
                                 errors = true;
                             });
        Console.WriteLine("archivo {0}", errors ? "No cumple con la validacion" : "validacion exitosa");
        Console.ReadKey();
    }
}
VhsPiceros
  • 410
  • 1
  • 8
  • 17
  • The Validate method is an extension method that can be used using the `System.Xml.Schema` namespace. – Taher Dec 03 '22 at 07:04