我有這樣的代碼:爲什麼XmlDocument Validate事件處理程序沒有被擊中?
// Load the document
XmlDocument xmlDocument = new XmlDocument();
// use the stream and have it close when it is finished
using (argInputStream)
{
xmlDocument.Load(argInputStream);
xmlDocument.Schemas.Add(XmlSchema.Read(argSchemaStream, null));
xmlDocument.Validate(ValidationEventHandler);
}
// this is not getting hit
void ValidationEventHandler(object sender, ValidationEventArgs e)
{
switch (e.Severity)
{
case XmlSeverityType.Error:
Console.WriteLine("Error: {0}", e.Message);
break;
case XmlSeverityType.Warning:
Console.WriteLine("Warning {0}", e.Message);
break;
}
}
頂線我的XSD的:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
任何想法?
由於您的文檔是有效的,也許? –
我已將其設爲無效。 –