1

I am developing a web service to validate an XML file against XSD file. I have to use this web service in another application. The function that validates XML is:

public string validate(String xml_file, string xsd_file)
{
    XmlSchemaSet schemas = new XmlSchemaSet();
    schemas.Add(null, xsd_file);

    XDocument custOrdDoc = XDocument.Load(xml_file);

    string error_msg = "no error";

    custOrdDoc.Validate(schemas, (o, e) =>
    {
        error_msg = e.Message;

    });

    return error_msg;
}

When this web service is used in an application, it returns "no error" for all inputs, even if the xml and schema files do not match. Please help me with this.

1 Answers1

0

I believe the problem you are having may have to do with using different namespaces in the document and schema. Please see here:

XDocument.Validate namespace problems

I have had success using XmlDocument to validate in the past and I believe it does not have the same problems.

http://msdn.microsoft.com/en-us/library/ms162371(v=vs.110).aspx

Community
  • 1
  • 1
DWCP
  • 136
  • 1
  • 4