Check for well formedness and get all errors

Hi

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.

My code is, off course, very simple:
XmlTextReader xtr = new XmlTextReader(xmlInstanceTextBox.Text);
try
{
while (xtr.Read())
{}
}
catch (Exception e)
{
errors += e.Message;
}
finally
{
xtr.Close();
}

When doing a validating reader, I can get an event everytime an
exception occurs, and keep running. But this one... it seems that
there is now way?

Any thouhgts?

Thanks in advance!

0
eliasen42 (5)
8/21/2007 7:17:24 AM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
668 Views

Similar Articles

[PageSpeed] 16

eliasen wrote:

> 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.




-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/21/2007 12:32:19 PM
> > 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.

In .NET 1.1 I created a small program that used the
XmlValidatingReader. This could continue after a validation error had
occurred and I could get all the errors. In .NET 2.0 I created this
code and I can't seem to get all the errors:

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_ValidationEventHandler);

                //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? (Yes, I can use the XmlValidatingReader, but it would be nice to
not use deprecated classes :-) )

Thanks!

0
eliasen42 (5)
8/21/2007 1:06:26 PM
eliasen wrote:

> 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_ValidationEventHandler);
> 
>                 //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? 

Your code should do, only you need to make sure that your use the 
bitwise or operator '|' on the flags e.g.

                 settings.ValidationFlags |=
XmlSchemaValidationFlags.ProcessSchemaLocation;

If you still have problems then tell us exactly what is happening, 
whether you get an exception, which one exactly.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/21/2007 1:40:44 PM
On Aug 21, 3:40 pm, Martin Honnen <mahotr...@yahoo.de> wrote:
> 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
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?

Thanks!

--
eliasen

0
eliasen42 (5)
8/21/2007 1:56:49 PM
eliasen wrote:

> 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?

I don't think it is a fatal error in the sense that parsing is aborted.
It might simply be that the parser has difficulties to find the right 
position in the source and the schema to continue validation.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/21/2007 2:07:10 PM
Reply:

Similar Artilces:

access to http://servername/help/default.aspx is denied: HTTP Error 401.2
On the productive CRM installation the help button on top right of each form, does not show the requested help, but an error message, that access is denied. http://servername/help/default.aspx HTTP Error 401.2 - Unauthorized: Access is denied CRM Server is installed on 64-bit Windows server 2008 R2. For the rest there are no access denied errors on the crm itself. On our development installation on a 32-bit windows server 2003 there is no such problem. Who can give me a hint? Patrik Vogel Is the "Help" Virtual Directory under the CRM website using CRMAppPool? how about...

merge MSN Bill Pay & Checking Acct
I want to merge my checking account with MSN Bill Pay but only see that I can merge MSN Bill Pay with my checking account (i.e., you lose all of your checking account information). Does any one have any suggestions? -- cheers, Tom G ...

DLookUp #Error
Hello Could anyone help me solve this problem please? I have been looking at this expression for an hour and just couldn't figure out where the problem is. =DLookUp("TotalUnit","OpeningBal","[ProductName] = " & [ProductName]) This expression is in a report where I would like to pull some total number for each product out of a query "openingbal" The openingbal query is as follows, the txFrom datetime value is provided. SELECT ProductName, Sum(nz([Purchased])-nz([Given])) AS TotalUnit FROM Transactions WHERE TransactionDate<Form...

Authorizing checks with RMS
I recently removed PCCharge and setup my syetm to work with a preferred merchant provider to allow native processing of credit & debit cards. Since check verification/authorization was handled by PCCharge to Telecheck, check authorization is now not being done. How is check authorization accomplished using a preferred provider? Thanks, Richard Unfortunately, it's not. PC Charge is the only option for check processing in RMS as far as I know. TPI or some other vendor may support it through an add-in, but RMS as shipped has no way of doing both checks and debit... -- -- Gle...

401k Updiate Retirement Account Error
I am receiving an error on only 1 of my 3 401k accounts whenever I go into "more investing tasks" --> "update retirement account" in MS DLX 2007. The specific error is a dialogue box that says "This operation cannot be performed" and then prompts me for more info which takes me to this link: http://moneycentral.msn.com/money/2004/ee.asp?ProdVer=16.00.120.1024&FileName=ObRes.dll&FileVer=16.00.1024&EvtSrc=16.0&EvtId=obres:34&LCID=1033 Furthermore, this dialogue box provides me an "ok" and "more info" button. The "...

Check names not working for multiple address books / contacts
Hello! I have upgraded from outlook 2003 to outlook 2007, my contacts are stored in pst. I used to be able to search for a name via check names and it displayed me all the results from global address list and from my contacts, but now it only does one. It does not matter which one I set in the checking order, whichever is top will be the one that provides the result. I would like it to show me both results, how would I go about to set that up? Thank you Deana More accurate and complete information would be helpful. The Global Address List is only available to those who c...

Best way to get started with VBA?
Hi. A lot of replies by the MVPs include the statement that the OP will need to use VBA. What's the best way to get started? Are there any "VBA for Dummies" type books or development tools? Are there repositories of source code that the beginning VBA programmer can look at? Question: Does Outlook (2003) out of the box contain VBA code that is executed when a user clicks on a button or fills out a form? While Outlook is running, is there a way to watch this code execute and see how it changes values or fills in fields? This question came up in my mind because of the dedica...

How do I create Check list
1.I am new to excel and want to create a simple check list. I would like to have the first column check boxes and then the following columns discription and notes. Can someone give me a step by step on how to do this. I have created spread sheets but am not familiar with check boxes. 2.Also, Can someone tell me the difference between Access and Excel? Geek 1) Not sure what you're aiming to do with the checkboxes, but if you right click on the toolbar area, you will get a list of available toolbars. You want either the 'forms' toolbox or the 'controls' toolbox. Genera...

Check text field value against underlying table or query of combo box
Hello, I have a form on which the user can enter new records or update existing ones. If the user enters a new record on the form, I would like to have an 'After Update' event on one of the text fields, which is the item# to check if the value entered already exists in the underlying table, tbl_item. How can I call the table from the 'After Update' event of the text field and check for that value in the table? Thanks in advance. Regards, A. Crawford antcraw@swbell.net wrote: >I have a form on which the user can enter new records or update >existing ones. >If the us...

Preventing multiple check boxes from being checked
I have a worksheet with over 20 rows of check boxes with 5 check boxes in each row. (from the forms toolbox) I would like to prevent the user from checking more than one box in each row. Is this possible? BTW, this forum has been a great help. I'm so glad that expert Excel users are so willing to share their wealth of knowledge. Thanks again. Jae Put them in a group box, again from the forms toolbar. Drag the group box onto the sheet, then drag the checkboxes in. -- HTH RP (remove nothere from the email address if mailing direct) "Jae" <Jae@discussions.micro...

Printing Checks
I'm having a problem printing checks from Money 2003. I have three accounts that come up in one .mny file. Two of the accounts use 3-on-a-page checks and I want the name and address printed on them. One account uses voucher checks and needs to be nudged a little south. When I go to print checks I have to be aware of what account I'm in and change the settings by hand to make sure the checks print correctly. How can I make the check-print settings stick with the account I'm using. It's a pain to have to remember every time. I'm frequently forgetting and screwing up a pag...

554 error client host rejected wrong mail relay using Exchange 2003 /w SP2
I seem to be getting this error on a few domains that I'm sending mail to. We are using Windows 2003 /w Exchange 2003 SP2. Any idea's? Is this caused by a external DNS issue on the A or PTR record? Or... In external DNS we have our email server setup as mail2.abc.com but within Exchange we have our email server setup as mail1.abc.com would this be causing the issue? The following recipient(s) could not be reached: john@abc.com on 21/04/2006 9:54 AM There was a SMTP communication problem with the recipient's email server. Please contact your system ad...

Employee Check Format-Graphical
Does anyone know of a TK that shows how to convert one of the employee check from a text report to a graphical report? We do not have Direct deposit, I looked in the Report Downloads from Great Plains and did not see one there either. thanks -- Doug There's no secret here. Just un-check the "Text Report" option in the Report Definition window. And then modify the report so it looks like you want it. This will take some time. The reports don't transfer from text to graphical nicely. "Doug" wrote: > Does anyone know of a TK that shows how to convert...

GET PIVOT DATA
Just upgarded Excel version. In my previous version I had no trouble adding cells displayed in the PT. Assuming I have cell A,B&C inside the PT In D I just sum (+AI+B1+CI) However the upgraded version does not allow me to do this. Instead It starts with +GETPIVOTDAT(cell). This is too long and I also have trouble copying down because it seems to be hard coded only to D1. Cell D2, D3 etc will show same formula as D1. Tried to look up in Help but does not show how I can "disable" this and use back the earlier formula. This can be done but I have to manually type in t...

Simple hack to get $500 to your home. 06-04-10
Simple hack to get $500 to your home at http://dailyupdatesonly.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. On 6/4/10 12:58 PM, kajol wrote: > Simple hack to get $500 to your home at <URL DELETED> > > Due to high security risks,i have hidden the cheque link in an > image. in that website on left side below search box, click on image > and enter your name and address where ...

Check Names = "Exchange Server computer is busy..."
Here's what I got: Active Directory on Server 2003 1 Domain Controller also running DNS and WINS No other DNS or WINS servers (I know, I know) Static IP Addresses...NO DHCP Exchange Server 2003 on a member server Client running W2K SP4 Outlook 2000 SP3 Exchange has 4 mailboxes set, but nobody is using it. I'm still testing things out. When I try to connect to Exchange via my Outlook 2000, I get the following message: "The function cannot be performed because the Microsoft Exchange Server computer is busy. Try again later" I've tried it from 3 different client comp...

Printing MICR checks
Hello, We are having an issue printing checks on the Select Payables Checks window. When we try to print the checks we receive the error message below: "Warning: You have MICR but are not in a MICR screen. To use MICR, abort this screen and set up security access." The user has access to this screen but I'm not sure what this error message means. There was nothing related to this in the Knowledge Base either. Has anyone else received this error message before and if so how did/do you resolve it? Thanks! The user has the third party mekorma check writing module ...

Errors after Service Pack 2
I am getting a lot of the following errors on my exchange 2003 after Service pack 2 was installed: Event ID: 7515 Source: MSExchangeTransport Description: An error occurred while Microsoft Exchange Intelligent Message Filter attempted to filter a message with ID <faf101c5f47a$f3044d20$5c34000a@XXX.XXX>, P1 From smtp:XXXX@XXX.com and Subject Reading One for SOW 340. This message will not be filtered. The error code is 0x800710f0. i found another thread with someone having the same problem microsoft acknowledged this as a bug with imf not being able to scan messages large...

SFO client install error 02-03-05
hello... i have got a problem that the shortcuts and the crm icon in the mail box will not show out when i install the SFO client software and I got the error message "Setup has failed because of an error. Setup unable to install the .msi file for Microsoft CRM SFO" I have tried to uninstall the software many time, even i changed the Domain but the problem still happened. does anyone get the idea how to resolve it? Thanks Jerry, Be sure you followed all of the pre requisites before the install is attempted. Make sure the web client is operational. Indexing services are in...

Check off boxes
Publisher 2003 in use. I am creating a questionnaire that will be included in a newsletter. I am using the publisher software to make this form. Somewhere, in the past, I saw a keyboard shortcut to inset checkoff boxes, however, I cannot remember the key strokes. Any help along this line will be greatly appreciated. Thank you and enjoy your day. Mike Mike Reshetar wrote: > Somewhere, in the past, I saw a keyboard shortcut to inset checkoff boxes, > however, I cannot remember the key strokes. Use Wingdings and the � or q characters. -- Ed Bennett - MVP Microsoft Publisher h...

Toolbar button error?
In Excel 2003 I put a button on a custom toolbar - the button is the 'double bottom border' and is from the Customise-Format selection of buttons. However this button just gives me a single bottom border. I can get double borders in other ways, e.g. from the drop-down borders box, where the identical-looking button does give me a double bottom border. Is this an error, or am I missing something? Thanks, David Wheeler d.r.wheeler@btinternet.com Hi David does the same for me too ... so i think it's broken :( and while this is no help at all to you i'll say it anyway ...

check check check
afpoiadshfpaosid It is a feature, not a bug -- Message posted from http://www.ExcelForum.com ...

datagrid bound to dataset is only getting 50 chars
I have a memo field in an ACCES database (up to 650000 characters). I have set up an adapter and a dataset for the database. I have a datagrid bound to the dataset. There are 4 fields in the datatable. The "Codetext" field which should be the memo only gets the first 50 characters from the database. Is it the schema generated by Visual Basic ? Here is the schema: <?xml version="1.0" standalone="yes" ?> - <xs:schema id="DsCodeKeeper" targetNamespace="http://www.tempuri.org/DsCodeKeeper.xsd" xmlns:mstns="http://www.t...

spam properties check
When I receive a suspecious email (spam), I right click, without opening the message, to check the properties to make sure it is spam before I forward to the "missed spam" software of my ISP. Some spam emails then ask me if "I want to save the changes" before I close the properties box. I am then not able to forward this email without replying yes to "save the changes?" I did not make any changes, I just checked the properties. Why is this happening? ...

Get info from changing cell to static cell
Hi, let me explain... I have a link from the web which is a share price. I would like to record the last 3 price changes and then average of all three. ( price changes can happen in seconds or minutes) I believe I am looking to copy the content initially as a static value(cell1), when it changes to copy it to another static cell (cell3), when it changes again copy this to another static cell (cell3)... I hope this is clear enough I can work out the average...lol The next stage would be average of another change, cell 2 + 3 + 4 but lets get the initial problem first... :-) TIA It...