I'm trying to validate my stream of xml via an XMLReader, but it is saying it can't find the elements when they're clearly in the xsd file.
When it gets to the part While Xrdr.Read(), it goes into the validation event and gives me the error. It's like it's not recognizing the schema. Am I missing a setting?
Thanks much.
error:
Could not find schema information for the element 'Ping'.
partial xsd file:
<xs:element name="Ping" type="xs:boolean" />
When it gets to the part While Xrdr.Read(), it goes into the validation event and gives me the error. It's like it's not recognizing the schema. Am I missing a setting?
Thanks much.
error:
Could not find schema information for the element 'Ping'.
partial xsd file:
<xs:element name="Ping" type="xs:boolean" />
Code:
public XmlSchema GetSchema()
{
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("[URL unfurl="true"]http://tempuri.org/DetailsSchema1.xsd",[/URL] "C:/Projects/ReplyEnterpriseBusiness/ReplyEnterpriseBUS/DetailsSchema1.xsd");
schemaSet.Compile();
XmlSchema detailsSchema = null;
foreach (XmlSchema schema in schemaSet.Schemas())
{
detailsSchema = schema;
}
return detailsSchema;
}
public Boolean ValidateXML(MemoryStream mstr)
{
XmlReaderSettings xRdrSettings = new XmlReaderSettings();
XmlSchema xSchema = GetSchema();
xRdrSettings.Schemas.Add(xSchema);
xRdrSettings.ValidationType = ValidationType.Schema;
xRdrSettings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
xRdrSettings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
mstr.Position = 0;
XmlReader xRdr = XmlReader.Create(mstr, xRdrSettings);
while (xRdr.Read()) ;
return true;
}
private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
string message = "";
message = e.Message;
//return message;
}