المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : validating xml and ignore some elements with out changing schema



C# Programming
07-05-2009, 10:32 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):








thanks in advanced,
A Y