473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlReaderSettin gs ValidationEvent Handler Firing Twice

I have an issue with the EventHandler for the XmlReaderSettin gs object being
called twice during validation and I'm a little stumpped as to why. The
error message being given is the same error message both times. This is an
intentional error that I have introduced into the XML file to test my
validation code so the second time it occurs is definately invalid and
should not occur (I have successfully tested the valid version of the XML
file). My XML file has references to about 3 other namespaces. My XSD that
I am using references about 4 other namespaces and redefines one of the
namespaces for half of it's use. I'm wondering if this redefinition and the
way the schema is written is causing the XmlReaderSettin g object to find the
namespace twice and thus fires the event twice, but I can't confirm this.
The reason I think this is the problem is because when I step through the
Event Handler code (i.e. F11) the control never leaves the method, rather it
steps back to the top of the EventHandler like the event was raised a second
time. I have checked my code and the EventHandler is only being assigned
once. It's not being assigned behind the scenes either, as when I comment
out the EventHandler assignment I get the expected
XmlSchemaValida tionException which is the less graceful exit path. Has
someone seen this before or can confirm that a schema namespace being
declared twice in an XSD would cause this type of problem in an
XmlReaderSettin gs object? I have encluded some sample examples of both XSD
and code used to validate the XML file. Any help would be appriciated.

<xsd:schema xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:abc="http ://www.ABC.org/schemas"
xmlns:abc-tp="http://www.ABC.org/schemas/Types"
xmlns:order="ht tp://www.ACME.com/schemas"
targetNamespace ="http://www.ACME.com/schemas" elementFormDefa ult="qualified"
attributeFormDe fault="unqualif ied">

<xsd:import namespace="http ://www.ABC.org/schemas"
schemaLocation= "ABC.xsd"/>
<xsd:import namespace="http ://www.ABC.org/schemas/Types"
schemaLocation= "ABC_Types. xsd"/>

<xsd:redefine schemaLocation= "Header.xsd ">
<xsd:simpleTy pe name="schemaNam eString">
<xsd:restrictio n base="order:sch emaNameString">
<xsd:enumeratio n value="ACMEOrde r"/>
</xsd:restriction >
</xsd:simpleType>
...... <!-- More ReDefinitions Here -->
</xsd:redefine>

<!-- Start using the targetNamespace here as opposed to the ACMEOrder
reference -->
<!-- to the same namespace up above in the ReDefinition section -->
<xsd:element name="Order"></xsd:element>
<xsd:element name="StartDate " type="xsd:date" ></xsd:element>
<xsd:element name="EndDate" type="xsd:date" ></xsd:element>
</xsd:schema>

private void ValidateSchema( )
{
xssXmlSchemaSet = new XmlSchemaSet();
xrsXmlReaderSet tings = new XmlReaderSettin gs();

xssXmlSchemaSet .Add("http://www.ACME.com/schemas", @"C:\Order.xsd" );
xrsXmlReaderSet tings.Validatio nType = ValidationType. Schema;
xrsXmlReaderSet tings.Validatio nEventHandler += new
ValidationEvent Handler(xrsXmlR eaderSettings_V alidationEventH andler);
xrsXmlReaderSet tings.Schemas = xssXmlSchemaSet ;

xtrXmlTextReade r = new XmlTextReader(@ "C:\OrderDoc.xm l");
xrReader = XmlReader.Creat e(xtrXmlTextRea der, xrsXmlReaderSet tings);
using (XmlReader xrXmlReader = XmlReader.Creat e(xrReader,
xrsXmlReaderSet tings))
{
while (xrXmlReader.Re ad()) ;
}
}

private void xrsXmlReaderSet tings_Validatio nEventHandler(o bject sender,
ValidationEvent Args e)
{
msErrorMessage = msErrorMessage + e.Message + "\r\n";
miErrorsCount++ ;
}


Mar 19 '07 #1
2 5273
Techno_Dex wrote:
private void ValidateSchema( )
{
xssXmlSchemaSet = new XmlSchemaSet();
xrsXmlReaderSet tings = new XmlReaderSettin gs();

xssXmlSchemaSet .Add("http://www.ACME.com/schemas", @"C:\Order.xsd" );
xrsXmlReaderSet tings.Validatio nType = ValidationType. Schema;
xrsXmlReaderSet tings.Validatio nEventHandler += new
ValidationEvent Handler(xrsXmlR eaderSettings_V alidationEventH andler);
xrsXmlReaderSet tings.Schemas = xssXmlSchemaSet ;

xtrXmlTextReade r = new XmlTextReader(@ "C:\OrderDoc.xm l");
xrReader = XmlReader.Creat e(xtrXmlTextRea der, xrsXmlReaderSet tings);
using (XmlReader xrXmlReader = XmlReader.Creat e(xrReader,
xrsXmlReaderSet tings))
{
while (xrXmlReader.Re ad()) ;
}
}
Why do you need all those readers, does
using (XmlReader xmlReader = XmlReader.Creat e(@"C:\OrderDoc .xml",
xrsXmlReaderSet tings))
{
while (xmlReader.Read ()) {}
}
not suffice?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 20 '07 #2
Much obliged. In my attempt to learn and piece together the new v2.0 Xml
parsing and validation functionality I merged code from two different
sources and in the process completely blew past the fact that I was using
two XmlReaders (one instantiated from the other) tied to the same
XmlReaderSettin gs object. It makes complete logical sense now as to why I
was receiving the event twice.
..
"Martin Honnen" <ma*******@yaho o.dewrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Techno_Dex wrote:
>private void ValidateSchema( )
{
xssXmlSchemaSet = new XmlSchemaSet();
xrsXmlReaderSet tings = new XmlReaderSettin gs();

xssXmlSchemaSet .Add("http://www.ACME.com/schemas", @"C:\Order.xsd" );
xrsXmlReaderSet tings.Validatio nType = ValidationType. Schema;
xrsXmlReaderSet tings.Validatio nEventHandler += new
ValidationEven tHandler(xrsXml ReaderSettings_ ValidationEvent Handler);
xrsXmlReaderSet tings.Schemas = xssXmlSchemaSet ;

xtrXmlTextReade r = new XmlTextReader(@ "C:\OrderDoc.xm l");
xrReader = XmlReader.Creat e(xtrXmlTextRea der, xrsXmlReaderSet tings);
using (XmlReader xrXmlReader = XmlReader.Creat e(xrReader,
xrsXmlReaderSe ttings))
{
while (xrXmlReader.Re ad()) ;
}
}

Why do you need all those readers, does
using (XmlReader xmlReader = XmlReader.Creat e(@"C:\OrderDoc .xml",
xrsXmlReaderSet tings))
{
while (xmlReader.Read ()) {}
}
not suffice?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Mar 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6506
by: pawel.pabich | last post by:
Hajo, I want to validate xml against DTD but I am not able to load DTD schema. My code looks like that: XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; settings.ValidationType = ValidationType.DTD; settings.ValidationEventHandler += new
2
3851
by: alien2_51 | last post by:
Can some one tell me why the onclick is firing twice for the radion button and checkbox controls...? <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Testing.aspx.vb" Inherits="CustomerRelations.Testing" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>Testing</title> <!--
4
6075
by: Larry Morris | last post by:
The following code, pasted into a web form with a link button on it, will cause the page_unload event to fire twice. If I remove the response.redirect, the problem goes away :). I've got a work around, but I'm curious how one is supposed to programmatically navigate between web pages without the page_unload event firing twice. Thanks, ...
4
3957
by: Seraph | last post by:
Again, I'm rather new here, so if I fail to follow any etiquette, please forgive me and let me know what I've done wrong, but I think this might interest quite a few people. One of my colleaques was endeavoring to create a custom user control to make things a bit simpler, but she noticed that her Page_Load eventhandler was firing twice. So...
28
10233
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event...
4
7891
by: Brian P | last post by:
I have a service that is driven by a timer that fires every 5 seconds. For the most part, it works fine. But every once in a while the timer fires twice. In the log I can see that when it fires twice, there are two threads running. This causes problems so I need to find a way to fix it. So, my question is, do I need to use a Monitor to...
0
2628
by: Jen | last post by:
My main question: "How can I get a TextReader or Stream object from an existing XmlReader?". Read on for more: I have an existing XmlReader. Let's call it reader1. I'm creating another reader, reader2, after creating new XmlReaderSettings and a new XmlParserContext. // customContext and customSettings may or may not make use reader1's...
4
4279
by: ShaneFowlkes | last post by:
I have a odd thing happening. I have a sub that is called upon a button click and it seems to be firing TWICE. I have no idea how this is happening but I suspect is has something to do with page_load and IsPostBack. The page has a form that displays a record. The user can delete the record by clicking a delete button or update it by...
14
8651
by: TS | last post by:
I have this custom data list control and i override the onItemDatabound event. After upgrading to vs 2005, this event is not always getting called, though it does at other times. No changes were made when upgrading to 2.0 is there any reason for this because of .net 2.0? thanks
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.