How to ignore part of xsd
-
Sunday, July 05, 2009 5:56 AM
Hi ,
I am validating an xml that express an an invoice document.
this documnt always have header and lines.but somtimes (not always) have serial numbers.
When I am validating the xml against the shcema I want the validator to ignore if the serial number element does not exist.
I can't change and I don't want to change the schema Since i am getting it from a third party software.
What can I do to ignore it?
see, my code and a part of the schema below:
I am using this code to validate xml file to xsd file:
private void ValidateSchema(string filePath)
{
XmlReaderSettings settings;
XmlDocument doc;
XmlReader reader = null;
try
{ settings = new XmlReaderSettings();
settings.Schemas.Add(null, m_sSchemaPath);
settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler);
settings.ValidationType = ValidationType.Schema;
doc = new XmlDocument();
reader = XmlReader.Create(filePath, settings);
doc.Load(reader);
doc.Validate(settings_ValidationEventHandler); }
finally
{
reader.Close();}
}
this is part of the the XSD(a few complex type elements):
a.y- Moved by Bin-ze Zhao Wednesday, July 08, 2009 8:58 AM off topic (From:Visual C# General)
All Replies
-
Tuesday, March 23, 2010 6:12 AMAnswererUnfortunately, there is no way to continue processing after errors have been found. A possible workaround could be to selectively modify the schema in-memory, using the Schema Object Model (SOM), if you want to preserve the original .xsd files as-they-are.
-
Wednesday, April 07, 2010 2:08 PM
Hello,
If you can't control the schema, it seems that you just have to live with the invoice not validating against it. What prevents you from creating and using your own version of the schema? Or could you create your own version, and validate against it only if validating against the first schema fails.

