我构建了一个针对 XSd 验证 xml 文件的应用程序。如果在一个节点中发生错误,它会引发异常,在该异常中我只能获得行号和行位置。如何获取该节点的最大长度值。
MemoryStream xml = new MemoryStream();
string xsd;
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("", Application.StartupPath + "\\std_imaging.xsd");
settings.ValidationEventHandler += MyValidationEventHandler;
var v = XmlReader.Create(filename, settings);
while (v.Read())
{
string a1 = v.ValueType.Name.Length.ToString();
string name = v.NodeType + v.Name + v.ValueType + v.Value.ToString();
}
public void MyValidationEventHandler(object sender, ValidationEventArgs args)
{
schemaResult = false;
textBox1.Text = textBox1.Text + (Environment.NewLine + args.Message +
Environment.NewLine + "Location(" + args.Exception.LineNumber +
"," + args.Exception.LinePosition + ")" + Environment.NewLine);
}
this is my code.