473,326 Members | 2,076 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,326 software developers and data experts.

Looping through XML in asp.net

I'm trying to extract data from a simple XML document that holds the data in 2 levels by looping through the levels. Simplified code is:

Dim doc As New XmlDataDocument
Dim strngs As String, strng1 As String, strng2 As String
Dim Node1 As XmlNode, Node2 As XmlNode

strngs = "<ABC><XYZ>Smith<EFG>Jim</EFG><EFG>Freddy></EFG><EFG>Bill</EFG></XYZ><XYZ>Jones<EFG>Gill</EFG><EFG>Jack</EFG></XYZ></ABC>")

doc.LoadXml(strngs)

For Each Node1 In doc.DocumentElement.ChildNodes
Response.Write(Node1.ChildNodes(0).InnerText)
If Node1.HasChildNodes Then
For Each Node2 In Node1.
Response.Write("Node2.ChildNodes(0).InnerText")
Next
End If
Next
Problem is the code trips up at the second 'Node2.ChildNodes(0).InnerText line.' If I remove the reference to Childnodes(0) it works but I get an extra data line reading '#text' at each pass of the second loop. It seems to be trying to pick up the data from the node above - I can make it work by chopping out the first pass of each second loop but this seems a cumbersome thing to have to do.

I've missed something very simple here I think!

Any ideas - thanks in advance.
Nov 12 '05 #1
2 7581
Update -
I wrote the simplified code incorrectly -

Response.Write("Node2.ChildNodes(0).InnerText") should read:

Response.Write(Node2.ChildNodes(0).InnerText)

This hasn't tresolved the problem though as it was merely a typo when I wrote the posting.

"BeWyched" wrote:
I'm trying to extract data from a simple XML document that holds the data in 2 levels by looping through the levels. Simplified code is:

Dim doc As New XmlDataDocument
Dim strngs As String, strng1 As String, strng2 As String
Dim Node1 As XmlNode, Node2 As XmlNode

strngs = "<ABC><XYZ>Smith<EFG>Jim</EFG><EFG>Freddy></EFG><EFG>Bill</EFG></XYZ><XYZ>Jones<EFG>Gill</EFG><EFG>Jack</EFG></XYZ></ABC>")

doc.LoadXml(strngs)

For Each Node1 In doc.DocumentElement.ChildNodes
Response.Write(Node1.ChildNodes(0).InnerText)
If Node1.HasChildNodes Then
For Each Node2 In Node1.
Response.Write("Node2.ChildNodes(0).InnerText")
Next
End If
Next
Problem is the code trips up at the second 'Node2.ChildNodes(0).InnerText line.' If I remove the reference to Childnodes(0) it works but I get an extra data line reading '#text' at each pass of the second loop. It seems to be trying to pick up the data from the node above - I can make it work by chopping out the first pass of each second loop but this seems a cumbersome thing to have to do.

I've missed something very simple here I think!

Any ideas - thanks in advance.

Nov 12 '05 #2
Update -
I wrote the simplified code incorrectly -

Response.Write("Node2.ChildNodes(0).InnerText") should read:

Response.Write(Node2.ChildNodes(0).InnerText)

This hasn't tresolved the problem though as it was merely a typo when I wrote the posting.

"BeWyched" wrote:
I'm trying to extract data from a simple XML document that holds the data in 2 levels by looping through the levels. Simplified code is:

Dim doc As New XmlDataDocument
Dim strngs As String, strng1 As String, strng2 As String
Dim Node1 As XmlNode, Node2 As XmlNode

strngs = "<ABC><XYZ>Smith<EFG>Jim</EFG><EFG>Freddy></EFG><EFG>Bill</EFG></XYZ><XYZ>Jones<EFG>Gill</EFG><EFG>Jack</EFG></XYZ></ABC>")

doc.LoadXml(strngs)

For Each Node1 In doc.DocumentElement.ChildNodes
Response.Write(Node1.ChildNodes(0).InnerText)
If Node1.HasChildNodes Then
For Each Node2 In Node1.
Response.Write("Node2.ChildNodes(0).InnerText")
Next
End If
Next
Problem is the code trips up at the second 'Node2.ChildNodes(0).InnerText line.' If I remove the reference to Childnodes(0) it works but I get an extra data line reading '#text' at each pass of the second loop. It seems to be trying to pick up the data from the node above - I can make it work by chopping out the first pass of each second loop but this seems a cumbersome thing to have to do.

I've missed something very simple here I think!

Any ideas - thanks in advance.

Nov 12 '05 #3

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

Similar topics

8
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per...
2
by: ensnare | last post by:
Hi all, I'm using a database session handler and am looking to loop through data residing in the sessions table to make a 'Users online' array. I've found that using urldecode on the data...
2
by: Ivo | last post by:
Hi, I have an audio file (.mid or .wav or .mp3) in an object element: <object id="snd" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"...
45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
5
by: masood.iqbal | last post by:
My simplistic mind tells me that having local variables within looping constructs is a bad idea. The reason is that these variables are created during the beginning of an iteration and deleted at...
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
5
by: johnb41 | last post by:
I need to loop through a bunch of textbox controls on my form. The order of the loop is very important. For example, the top one must be read first, then the one below it, etc. My first...
0
by: anthon | last post by:
Hi all - first post! anywho; I need to create a function for speeding up and down a looping clip. imagine a rotating object, triggered by an action, and slowly decreasing in speed, till it...
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
2
by: Davaa | last post by:
Dear all, I am a student making a MS Form application in C++. I would ask a question about "Timer". Sample code which I am developing is below. private: System::Void...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.