![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I would like to run through an XML file using C# 2.0 and check for well formedness - and I would like to get all errors and not jsut the first one. |
#3
| |||
| |||
|
|
I would like to run through an XML file using C# 2.0 and check for well formedness - and I would like to get all errors and not jsut the first one. |
#4
| |||
| |||
|
|
I would like to run through an XML file using C# 2.0 and check for well formedness - and I would like to get all errors and not jsut the first one. I think a well-formedness violation is a fatal error, XmlReader does not allow you to continue parsing. Bugger! :-) But thanks. |
#5
| |||
| |||
|
|
I would like to run through an XML file using C# 2.0 and check for well formedness - and I would like to get all errors and not jsut the first one. I think a well-formedness violation is a fatal error, XmlReader does not allow you to continue parsing. Bugger! :-) But thanks. |
#6
| |||
| |||
|
|
using (FileStream fs = File.Open(xmlInstanceTextBox.Text, FileMode.Open, FileAccess.Read)) { //GS - Create an xml document to hold our xml XmlDocument xdoc = new XmlDocument(); //GS - Create a reader settings, add the schema, set for //schema validation and add a validation event handler XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add(null, xmlSchemaTextBox.Text); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation; settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHan dler); //GS - Load and validate the xml XmlReader reader = XmlReader.Create(fs, settings); xdoc.Load(reader); //GS - Close the file stream when we're done fs.Close(); } and then off course an eventhandler that appends the error to a list of errors. Do you know how I can get all validation errors using .NET 2.0? |
#7
| |||
| |||
|
|
using (FileStream fs = File.Open(xmlInstanceTextBox.Text, FileMode.Open, FileAccess.Read)) { //GS - Create an xml document to hold our xml XmlDocument xdoc = new XmlDocument(); //GS - Create a reader settings, add the schema, set for //schema validation and add a validation event handler XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add(null, xmlSchemaTextBox.Text); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation; settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHan dler); //GS - Load and validate the xml XmlReader reader = XmlReader.Create(fs, settings); xdoc.Load(reader); //GS - Close the file stream when we're done fs.Close(); } and then off course an eventhandler that appends the error to a list of errors. Do you know how I can get all validation errors using .NET 2.0? |
#8
| |||
| |||
|
|
Your code should do, only you need to make sure that your use the bitwise or operator '|' on the flags e.g. Well, apparently, the code works. I tested it with two different |
#9
| |||
| |||
|
|
Your code should do, only you need to make sure that your use the bitwise or operator '|' on the flags e.g. Well, apparently, the code works. I tested it with two different |
#10
| |||
| |||
|
|
Well, apparently, the code works. I tested it with two different required elements missing... and only the first error appeared. But when I test it with invalid content in two different elements, it works well. Probably because the missing element is a fatal error as well? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |