473,698 Members | 2,149 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 5281
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
6512
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
3865
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
6090
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, Larry
4
3981
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 after long hours of research and experimentation, I stumbled upon, imho, is quite the discovery. ...
28
10261
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 is firing twice (95% of the time) on the page. the other 5% it only fires once. there's no
4
7916
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 lock in my timer_elapsed event handler? Thanks for any advice...
0
2634
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 properties XmlParserContext customContext = new XmlParserContext(...);
4
4287
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 clicking an update button. The delete sub calls a couple of other subs and functions and then displays a...
14
8672
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
8604
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.