473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Validation Error when Schema with Entities

Hi, I wrote a Schema Validator in C#.NET.

Expand|Select|Wrap|Line Numbers
  1.             XmlTextReader R = new XmlTextReader(FileToParse);
  2.             XmlValidatingReader V = new XmlValidatingReader(R);
  3.             try
  4.             {
  5.                 XmlSchemaCollection xsc = new XmlSchemaCollection();
  6.                 xsc.Add("", SchemaFile);
  7.                 V.Schemas.Add(xsc);
  8.                 V.EntityHandling = EntityHandling.ExpandEntities;
  9.                 V.ValidationEventHandler += new ValidationEventHandler(ShowValidationErrors);
  10.                 while (V.Read())
  11.                 {
  12.                 }
  13.                 //V.Close();
  14.                 //MessageBox.Show("Validation Completed");
  15.                 //R.Close(); 
  16.             }
  17.             catch (XmlException xe)
  18.             {
  19.                 //Display exceptions
  20.             }
  21.             catch (XmlSchemaException xse)
  22.             {
  23.                 //Display exceptions
  24.             }
  25.             catch (Exception ee)
  26.             {
  27.                 //Display exceptions
  28.             }
  29.             finally
  30.             {
  31.                 V.Close();
  32.                 MessageBox.Show("Validation Completed");
  33.             }
  34.  
This works fine if the xml file DOES NOT contain entity declarations.

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">
Sep 11 '07 #1
0 1317

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AlexS | last post by:
Hello, I have error when reading schema using XmlSchema. Read and then .Compile: System.Xml.Schema.XmlSchemaException: May not be nominated as the {substitution group affiliation} of any...
2
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
4
by: Wayne Wengert | last post by:
I have an XML document and a corresponding xsd document I built. I want to validate the xml document against that Schema but when I use the MSDN validator it has no place to select the xsd...
2
by: Marcin Cenkier | last post by:
Hi, I want to validate a DOM document, and if I build DOM from a stream using documentBuilder.parse() validation using validator.validate(DOMSource) works, but if I create the same document...
4
by: Igor Koretsky | last post by:
Hi. Using VB.Net System.Xml 1.0 SchemaCollection Object I am getting an error when trying to add ‘Schema A’ to the SchemaCollection. Here are my schema files..
8
by: SL | last post by:
I try to validate against a schema a document stored in several files thanks to external entities. The parseur add a 'xml:base="url"' attribute on the root element of this sub-trees during parsing,...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
6
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.