Expand|Select|Wrap|Line Numbers
- XmlTextReader R = new XmlTextReader(FileToParse);
- XmlValidatingReader V = new XmlValidatingReader(R);
- try
- {
- XmlSchemaCollection xsc = new XmlSchemaCollection();
- xsc.Add("", SchemaFile);
- V.Schemas.Add(xsc);
- V.EntityHandling = EntityHandling.ExpandEntities;
- V.ValidationEventHandler += new ValidationEventHandler(ShowValidationErrors);
- while (V.Read())
- {
- }
- //V.Close();
- //MessageBox.Show("Validation Completed");
- //R.Close();
- }
- catch (XmlException xe)
- {
- //Display exceptions
- }
- catch (XmlSchemaException xse)
- {
- //Display exceptions
- }
- catch (Exception ee)
- {
- //Display exceptions
- }
- finally
- {
- V.Close();
- MessageBox.Show("Validation Completed");
- }
But, If the xml file contains any entity declaration (as below), the 'ValidationEventHandler' throws errors like
"Validation Error: The 'mytest' element is not declared.Line : 8 Position : 2"
"Validation Error: The 'articles' element is not declared.Line : 9 Position : 2", etc.....
How do I overcome this in C#.NET
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE mytest
[
<!ENTITY a '<popup pos="ABBR.A"><i>a</i>.</popup>'>
<!ENTITY adv '<popup pos="ABBR.ADV"><i>adv</i>.</popup>'>
]>
<mytest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="X:\Schema\content.x sd">