473,385 Members | 1,730 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,385 software developers and data experts.

Help Reading XML file using XMLTextReader


My XML file
<FORMLIST>
<InsuredInfo>
<ANO>SR7501234</ANO>
<ADATE>02/05/2007</ADATE>
<InsName>SIRONA DENTAL SYSTEMS INC</InsName>
<POLNO>DOL7501234</POLNO>
<PEDATE>03/01/2007</PEDATE>
<PXDATE>03/01/2008</PXDATE>
<RevDATE></RevDATE>
<UndName>CAL</UndName>
</InsuredInfo>
<FORM>
<FORMNAME>A20072.002</FORMNAME>
<FORMTABLE>tblMergeMQ_PRNT</FORMTABLE>
<RECORDID>1</RECORDID>
<COUNTERSIGN>1</COUNTERSIGN>
</FORM>
<FORM>
<FORMNAME>A20072.002</FORMNAME>
<FORMTABLE>tblMergeMQ_PRNT</FORMTABLE>
<RECORDID>1</RECORDID>
<COUNTERSIGN>1</COUNTERSIGN>
</FORM>
<END>
<ENDNAME>D02419.000</ENDNAME>
<BLANKS>3</BLANKS>
<SPECIMEN>0</SPECIMEN>
<BLANKDATA>
<BLANK1>50,000</BLANK1>
<BLANK2>30,000</BLANK2>
<BLANK3>60,000</BLANK3>

</BLANKDATA>
</END>
<END>

</END>
</FORMLIST>

'Here is my current code

Private Sub ReadXml()

Dim objSettings As New XmlReaderSettings
objSettings.IgnoreWhitespace = True
objSettings.IgnoreComments = True

Dim objXMLReader As XmlReader = XmlReader.Create("X:\FormsMailMerge
\ProcessEndorsements\ProcessEndorsements\FormList. xml", objSettings)
Try

'objXMLReader.ReadToDescendant("FORM")

Do While objXMLReader.Read()
If (objXMLReader.Name = "InsuredInfo" And
objXMLReader.NodeType = XmlNodeType.Element) Then

objXMLReader.Read()
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
ElseIf (objXMLReader.Name = "FORM" And objXMLReader.NodeType =
XmlNodeType.Element) Then
objXMLReader.Read()
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
ElseIf (objXMLReader.Name = "END" And objXMLReader.NodeType =
XmlNodeType.Element) Then
objXMLReader.Read()
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)
Debug.WriteLine(objXMLReader.ReadElementContentAsS tring)

End If
Loop
Catch ex As Exception

Finally
objXMLReader.Close()
End Try

End Sub

Question is <BLANKDATA element can have different number of nodes.
How do I iterate through those noes (i.e. Blank1 , Blank2 etc.)
<BLANKDATA>
<BLANK1>50,000</BLANK1>
<BLANK2>30,000</BLANK2>
<BLANK3>60,000</BLANK3>
......
.....
</BLANKDATA>

Any suggestion on improving my code? Thanks in advance

Feb 13 '07 #1
0 2379

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

Similar topics

3
by: keldan | last post by:
I am hoping someone on this list can shed some light on the below issue for me. I am using XmlTextReader to read from an XML file. Unfortunately, an exception is thrown ("Index was outside the...
4
by: Drew | last post by:
I'm reading in an XML file from the server using XmlTextReader in C# like so: XmlTextReader xr = new XmlTextReader(url); while(xr.Read()) { //parse the xml file here
1
by: Damon Allison | last post by:
Hello, My program is being sent a large XML file, anywhere between 500k - 1MB. Of the entire file, I need to allow a user to view/edit approximately 5% of it. To make matters a bit more...
4
by: Oliver Sturm | last post by:
I have an XML file that contains fragments, meaning there's no root element. Node names are in my own "test" namespace. Looks like this: <test:info date="...">Content</test:info> <test:info...
1
by: Chua Wen Ching | last post by:
Hi there, I have some problems when reading XML file. 1. First this, is what i did, cause i can't seem to read "sub elements or tags" values, so i place those values into attributes like this....
1
by: adhag | last post by:
Hi I have an app that uses xpath to read an xml document. The problem is a 70meg file uses 1.5 gig of memory. What I really need is to read only chunks of the file at a given time and cannot...
6
by: Lloyd Dupont | last post by:
I have some XML file like that: === <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">...
3
by: Yehia A.Salam | last post by:
Hello, I am trying to read from an xml file and put it to a memory stream so I can read it multiple times from the beginning using XmlTextReader without accessing the harddisk , I tried using...
13
by: Rick | last post by:
The following code will enter an infinate loop when in ReadChars. I can only make it happen when reading a Stream and with this particular XML. If I use the ReadInnerXml call rather than my own...
16
by: billsahiker | last post by:
I am researching for an upcoming c# .net 2.0 project that may require reading and writing xml files. I don't want to use xmltextreader/ xmltextwriter as I prefer to have lower level file access...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...
0
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,...
0
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...

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.