I am fixing warnings in my program and obviously the xmlvalidating reader and xmlschemacollection is out of date. The problem is that I'm not quite sure how to do this. Here's an attempt to "emulate" the previous function of checking new with xmlschemaset and xmlreader.create. First, I declare the schema and set it using the targeturi string, and then add it to the schema when setting up the validation event handler. I think my problem is setting up readers and input streams. I knew how to do this with the xmlvalidating reader, but this is not an option if I want to fix these warnings. Here is the code and try. During testing, only the new xml verification code was used, the old one was commented.
string xsd_file = filename.Substring(0, filename.Length - 3) + "xsd";
XmlSchema xsd = new XmlSchema();
xsd.SourceUri = xsd_file;
XmlSchemaSet ss = new XmlSchemaSet();
ss.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
ss.Add(xsd);
if (ss.Count > 0)
{
XmlTextReader r = new XmlTextReader(filename2);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(ss);
settings.ValidationEventHandler +=new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create(filename2, settings);
while (reader.Read())
{
}
reader.Close();
}
XmlSchemaCollection sc = new XmlSchemaCollection();
sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
sc.Add(null, xsd_file);
if (sc.Count > 0)
{
XmlTextReader r = new XmlTextReader(filename2);
XmlValidatingReader v = new XmlValidatingReader(r);
v.ValidationType = ValidationType.Schema;
v.Schemas.Add(sc);
v.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
while (v.Read())
{
}
v.Close();
}
private void ValidationCallBack(object sender, ValidationEventArgs e)
{
isvalid = false;
MessageConsole.Text = "INVALID. Check message and datagridview table.";
richTextBox1.Text = "The document is invalid: " + e.Message;
}
, XML-, โโ: "" URNLookup " ". URNLookup xml. , .
. ! , -.
- tf.rz(.NET 3.5 SP1, Visual Studio # 2008)