XmlReader Question


I have a large unformatted document which needs to processed and
populated into DB.

For this, I was using an XMLTextReader to get valid IDs, and then doing
something like this:

 newRdr = xRdr.ReadSubtree();
                while (newRdr.Read())
                    if (newRdr.NodeType == XmlNodeType.Element)
                        switch (newRdr.LocalName)
                            case "A":
                            case "Y":
                            case "Z":                                
OutputXml.Append(newRdr.ReadOuterXml() + Environment.NewLine);

OutputXml is a stringbuilder which will get passed to DB.
This worked fine.

Now I need to do additional validation on the subtree and write passed
and failed subtrees to different locations.
I tried having 2 separate XMLReader, one getting the data from the nodes
and another for actually writing the outputs based on pass/fail, but the
second reader is also at the EndElement and hence empty.

newRdr = xRdr.ReadSubtree();
                validationRdr = newRdr;//xRdr.ReadSubtree();

                while (validationRdr.Read())
                    Data = validationRdr.ReadOuterXml();
                 Val1 = Data.Substring(...
                    Val2= DateTime.Parse(Data.Substring(....

if Val1> 0 && Val2> 0)
                            while (newRdr.Read())
                                if (newRdr.NodeType ==
//same switch statemtn

So it basically never hits the NodeType = Element line above.

Hope I have explained the problem clearly.

How do I validate and then read the data anyways?

*** Sent via Developersdex http://www.developersdex.com ***
12/9/2009 10:41:24 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 52

Ben wrote:

> So it basically never hits the NodeType = Element line above.
> Hope I have explained the problem clearly.
> How do I validate and then read the data anyways?

XmlReader works forwards only so you can't use it alone, you will need 
to store some of the XML.
Ways to do that are the ReadNode method of System.Xml.XmlDocument
or (in .NET 3.5) the ReadFrom method of XNode:

That way you could read the nodes that interest you into a tree 
structure, validate them and then save them (respectively their 
OuterXml) as needed.


	Martin Honnen --- MVP XML
12/9/2009 1:25:46 PM

Similar Artilces:

CStdioFile.ReadString question
Hello On a regular windows text file ReadString reads from a file until it sees 0D0A in hex terminating the line. In other files (for example UNIX text files and pdf files) a line is terminated only by 0D, but ReadString treats 0D not followed by 0A as normal character. What is the easiest workaround to this ? Peter ...

Exchange Server 5.5 IS Maintenance Question
Hi there, We have discovered that we need to allow the Information Store for Exchange Server 5.5 run and complete it's maintenance procedure. However, the problem is no matter how much time we give it, it still bogs down the server to the point of rendering it useless. For instance, we let it run from Friday at 7 pm to Sunday 5 pm and initiated our backup at 6 pm. When we came in Monday morning it was a total mess and the server had to be rebooted (something that cannot be afforded). My question is, there a way of segmenting the IS maintenance procedure or any other recommendations to...

Multi-Currency Question #2
Hello there, I would like to know why Customer balance is not adjusted automatically if I enter data with a different currency. For example if I enter 2000 in non-base currency as invoice with exchange rate of .0004 and pay it with exchange rate of .003, it shows that the customer still has balance of of 2 base. But I have paid all the non-base amount, but there are some Realized loss. Here is how I did: (All in in Non-Base Currency): Invoice: Qty Amount Total Currency Rate Base Amount(Calculated) 10 200 2000 .004 8 Pay...

Simple question #4
I'm relatively new to Excel and I want to creat a sheet for my expenses where I can enter a number in one column and have it subtracted from the above cell in the next column and so on, all the way down. I can do this by clicking on the bottom left of the cell and dragging it down but would like it to appear automatically. Sorry if that's not very clear. John In B1 enter the inital balance In A2 and on down enter your expenses In B2 enter: =IF(A2="","",B1-A2) and copy on down -- Gary''s Student - gsnu2007g "gtharwood@gmail.com" wrote: >...

CTabCtrl Question
Hi, all. I'm using a CTabCtrl (VC 6.0), and have a question on how to use it. Is there a way to add controls to specific tabs, so that each tabs associated controls are displayed if (and only if) that tab is selected? I know this is doable in something like VFP, but that's quite a horse of a different color. Or, do I just create controls (or dialogs?), hiding and and displaying them based upon the tab selection? If possible, a quick example of adding something like a button or text box would be extra helpful. Thanks in advance. Balboos I've never liked and used the CTab...

Basic Question
Hi all, I have a table called Companytbl with 2 fields: CompanyID (autonumber), CompanyName(text) On the form ( which related to a different table)I have company combobox. What exactly is the setup so on the combobox it will show the companyName and it will store in the table theCompanyID? TIA, Tom In news:%23Z%23x%23Q9JIHA.5928@TK2MSFTNGP05.phx.gbl, Tom <partner1973@yahoo.com> wrote: > Hi all, > > I have a table called Companytbl with 2 fields: CompanyID > (autonumber), CompanyName(text) > > On the form ( which related to a different table)I have company &...

Its a easy dumb question.
When i have formulas with there criteria not fullfilled, i get th "#N/A". How do i get that to go away -- comotoma ----------------------------------------------------------------------- comotoman's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2729 View this thread: http://www.excelforum.com/showthread.php?threadid=46828 comotoman Wrote: > When i have formulas with there criteria not fullfilled, i get th > "#N/A". How do i get that to go away? One way ... =IF(ISERROR(YOUR_FORMULA),\" \",YOUR_FORMULA will take care of th...

Case select question
Hi I have a case select code on my listbox. The listbox is called ReportID, I have an event procedure on dbl click. But when I dbl click the selection nothing happens. I have 2 columes of information that is shown in the list box, column 1 has report name, column 2 has report description. I put the report name in the case selection; from the table were reportID pulls information from did I write down the correct field information? Can anyone help me out? Private Sub ReportID_DblClick(Cancel As Integer) On Error GoTo handleErr Select Case Me!ReportID Case "Supply Plant Flour&...

ADMT question
When in the Security Translation Wizard of ADMT, concerning the user profiles security there is a "Replace" and an "Add". The docs for the ADMT push you to choose "Replace" with no real explaination. Would "replace" mean that what was there before would be "gone", meaing that you can never "go back" if something goes wrong? Wouldn't "Add" be the better choice if you are not confident that everything will go perfectly? -- Phillip Windell The views expressed, are my own and not those of my employer, ...

We have two users in our organization that we wish to limit the size of mail they sent to each other but no one else. Does anyone know how to do this? Thanks in advance, Michael "Michael Henderson" <mhenderson@nospam.amerlink.com> wrote: >We have two users in our organization that we wish to limit the size of mail >they sent to each other but no one else. > >Does anyone know how to do this? I don't think you can. But why look for a technical fix for the problem when a simple warning to them should suffice? Would you chain them to their desks if you found ...

The question of redemption
Latest News - http://investorline.co.in/blogger/?q=3Daggregator Investor's Knowledge Analysis - http://investorline.co.in/blogs/news/?p=3D8= 50 Due diligence must for MF investors who invest in equity schemes. Retail investors in mutual funds (MFs) have displayed surprising maturity, staying invested in equity schemes despite the sharp fall of the stock markets from mid-January. However, it is too early to conclude that Indians have graduated to becoming long-term investors in equity and equity MFs. Experience shows that retail investors panic whenever markets go into a tailspin, cashin...

Data Migration Question???
Hi We have been using MSCRM for over a year now. Recently there has surfaced a need to import a large number of Account records to the existing database. However, I have read that the Data Migration Framework cannot be used for merges and is for a one off migration. Does this mean I cannot add records to CRM using the DMF if I have data in the database? Or is it just a case of not being able to add records that relate to existing data? Could anyone shed some light on this matter? Thanks in advance You can certainly use DMF to import more data into an existing MSCRM database. You cann...

VBA codes question
Hi, I just write down some VBA codes for an application. What I need is extract some data from a selected area by mouse left-button. So what should I do ? The most I concerned is how to get the Range object of the shadow area selected by mouse. Thanks. ...

CreateProcess question
Hi, I am trying to write an application that will launch a second application using CreateProcess... SECURITY_ATTRIBUTES sa; STARTUPINFO si; PROCESS_INFORMATION pi; ::ZeroMemory( &sa, sizeof(sa) ); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; ::ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ::ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if ( !CreateProcess( NULL, "C:\\second_app.exe", &sa, &sa, TRUE, 0, NULL, "C:\\", &si, &pi ) ) { return; } ...

question on tables and queries
I've imported 2 tables from excel and ran a query against those two tables to determined the difference. This is something I would like to do each month. I would like to keep the same settings in my database, is there a way I can easily import/update the data in the new table without creating a new one each month? The query would stay the same as I'm comparing the same two files, but the the data will be changing every month. I don't know much about access and would like to know if there is an easier way of doing this besides creating a new table and query each month? I&...

I have a couple instances where I am using a set of data to define a window for testing purposes but I can't seem to find any place that really explains it. <Path Fill="#80D0E0FF" Stroke="Red" StrokeThickness="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M79,3L65,82 17,91 50,138 96,157 104,192 175,154 190,167 218,78 156,76 157,9 111,39z"/> In the Data attribute, I am trying to figure out what that means with the M's, Ls and z's. I have seen this shown ...

Question on mixing MFC and Winform
We had some problems (I posted earlier about overlapping windows that may be transparent, draw order etc). Well we got the drawing working more or less but there is quite a bit of flicker. I was curious if we switched to WinFroms if perhaps things might work better. Our app is an unmanaged MFC app (we don't really use any of the Doc/View support). I've started reading and researching mixing of WinForms with MFC. I'm curious if I replace the CView with CWinFormsView and then create child windows of the type CWinFormsControl if this may help. But I'm not finding mu...

Sales Tax set-up question
I have a tax set up problem with RMS. I am using the "per customer" tax configuration because we ship products out of state and out of country. Here is the situation: Ontario (local) customers pay GST (federal) and PST (state/provincial) Rest of Canada pay GST only Outside Canada pay no tax However, in Ontario some products are still non-taxable (which is no problem) and some are GST only (which is a problem). Is there a way to accommodate all of this? Also, if I have a customer who is from out of province (with an out of province address in RMS) but who visits my store in Ont...

Challenging Question
Hello All, We are Exchange 5.5 SP4. I have a user who has a Palm Treo 600 smartphone. We are wirelessly synchronizing with Exchange over the internet using Goodlink software from Good Technology. Desktop client is Outlook 2003. All is working fine except the "opened" status is not being synchronized to his handheld. All other changes (new mail, deletes, calendar) are being synchronized, so it doesn't appear to be a connectivity issue. Any ideas or suggestions or requests for further information would be much appreciated. (the person having the issue is our company preside...

another question on printing invoices.
Thanks to a suggestion here, I was able to graph out the spaces on the invoices properly, but I ran into another snag, here's the situation: I am tryinhg to figure out a way to print invoices from an excell spreadsheet. The invoices are pre-formated with fields and logos and are on continuous paper that is fed into a dot matrix impact printer. It's NCR paper, an original and two copies. The rows of the spread sheet contain the data that needs to be in the invoice. Each row has customer information, ie, name, address, item bought, price per unit, number of units, sales tax, and t...

Conditional Format question #2
SG93IGNhbiBJIGNyZWF0ZSBhIGZvcm1hdCBmb3IgdGhlIGNlbGxzIHdoaWNoIGNvbnRhaW5zIGEg Y2VydGFpbiBzdWJzdHJpbmc/ > How can I create a format for the cells which contains a certain > substring? Select col A (A1 active), then apply the CF using Formula Is: =ISNUMBER(SEARCH("diesel fuel",A1)) Format to taste > ok out Replace SEARCH with FIND if you need it to be a stricter, case sensitive search -- Max Singapore http://savefile.com/projects/236895 Downloads:19,000, Files:362, Subscribers:62 xdemechanik --- Cells being in column A use Format>Conditional formatting with this ...

next question about taskbar
Ok...another question for you: I created the tray icon and now it works as intended. However, I had to have a parent window for it. Because it was simpler to understand I used a MFC modal dialog as the parent window. However, I don't want to see the dialog. My thought was that I would use the dialog as a splash screen and then hide it, leaving the tray icon as the only visible indicator of my program. But now I'm stuck and I can't figure out how to hide the dialog. The only thing I'm trying to accomplish is to have the tray icon running on it's own. I don't need the dia...

Install question
I'm installing Dynamics GP 10 for the first time. It installs perfectly but when I try and launch it, it starts the utility screen and I can't login. During the install it asked for the SQL Server database name, which I provided, but the utility only lists Dynamics GP as the database and sa as the login option. None of my known logins for the default SQL Server 2005 instance are working. Any ideas? for the utilities, you MUST use the sa user, as an initial installation, there are no DYNSA users etc.... So: 1. Make sure your ODBC is setup properly 2. Make sure you know your sa pa...

Linking images questions
I am preparing my 16 page newsletter for publication on offset printing. Most images in the newsletter are jpegs, a few are TIFFs. Once I insert all the images, I will convert them all to "Process Colors: CMYK" under the "Commercial Printing Option." I have a few questions about inserting images. What is the advantage of "linking" an image instead of "embedding" it for offset printing? Also, if I do link an image to a file, do I have to size the image exactly as it will appear in the newsletter before inserting it or can I insert the image and ...

This is a multi-part message in MIME format. ------=_NextPart_000_000C_01C889AE.B8216410 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Whats the best way to tender out Gift Cards. This is the scenario. We re opening a new store and we will hand out 100 gift cards with 20$ on them. Whats the best way to tender that out in RMS. Do you create a store account and tender it out as a store account or is there a better way of doing that. Thanks. ------=_NextPart_000_000C_01C889AE.B8216410 Content-Type: text/html; charset="us-ascii" Content-Tran...