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

VB.net Out of scope loops - ChildNodes

Hi, I'm trying to loop through the nodes of my xml file. The info I need to get is located quite deep in about the fifth node but I want to incorporate in the output information that is located in my third node. The variable I get in my third node is out of scope in my fifth one. How do I do this? Your help is very much appreciated!

VB.net code:+++++++++++++


Expand|Select|Wrap|Line Numbers
  1. Try
  2.             Dim m_xmld As XmlDocument
  3.             Dim nodelist1 As XmlNodeList
  4.             Dim nodelist2 As XmlNodeList
  5.             Dim nodelist3 As XmlNodeList
  6.             Dim nodelist4 As XmlNodeList
  7.             Dim node1 As XmlNode
  8.             Dim node2 As XmlNode
  9.             Dim node3 As XmlNode
  10.             Dim node4 As XmlNode
  11.  
  12.             m_xmld = New XmlDocument()
  13.             m_xmld.Load("myxmlfile.xml")
  14.             nodelist1 = m_xmld.SelectNodes("adverts/advert")
  15.             For Each node1 In nodelist1
  16.                 nodelist2 = node1.ChildNodes
  17.                 For Each node2 In nodelist2
  18.                     nodelist3 = node2.ChildNodes
  19.                     If node2.Name = "a" Then
  20.                         Dim ref As String = ((node2.Attributes.GetNamedItem("name").Value).Substring(5, 6))
  21.                     End If
  22.                     For Each node3 In nodelist3
  23.                         nodelist4 = node3.ChildNodes
  24.                         For Each node4 In nodelist4
  25.                             If node4.Name = "title" Then
  26.                                 Dim titlevalue As String = "<a href='vacancy/index.htm?ref=" & ref & "'>" & node4.InnerText & "</a>"
  27.                                 Response.Write(titlevalue)
  28.                                 Response.Write("<br>")
  29.                             End If
  30.                         Next
  31.                     Next
  32.                 Next
  33.             Next
  34.         Catch errorVariable As Exception
  35.             Console.Write(errorVariable.ToString())
  36. End Try
  37.  
Xml nodes +++++++++++
Expand|Select|Wrap|Line Numbers
  1.  <adverts>
  2.    <advert>
  3.     <a name="d.en.118539" />
  4.      <vacancies>
  5.        <vacancy>
  6.         <multiadvertvacancy>no</multiadvertvacancy>
  7.         <singleadvertvacancy />
  8.         <reference>HUM/70208</reference>
  9.         <title>Job title</title>
  10.         <academicdepartment>Acad dept</academicdepartment>
  11.         <salary>salary info</salary>
  12.         <closingdate>29/06/2007</closingdate>
  13.         <interviewdate>04/07/2007</interviewdate>
  14.       </vacancy>
  15.     </vacancies>
  16.     <category>Academic</category>
  17.     <internal>no</internal>
  18.     <dateadded />
  19.   </advert>
  20.  </adverts>
  21.  
Oct 10 '07 #1
2 1238
Motoma
3,237 Expert 2GB
I have moved this thread to the .NET forum, as this seems to be an issue with your programming in VB.NET rather than your use of XML.
Oct 10 '07 #2
Hi, anybody? I am quite new to .net and xml so your help will be very much appreciated. Any ideas?
Oct 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
8
by: Zeng Dinghao | last post by:
int main() { for (int i=0; i<10; i++) { cout << "dfdfd" << endl; } for (int i=0; i<10; i++) { cout << "dfdfd" << endl; } } when compiling it in Visual C++, i got an error.
7
by: Michael G | last post by:
I am a little surprised that the following that $x is visible outside of the scope in which it is (?)defined(?) (not sure if that is the correct term here). I am trying to find where in the php...
8
by: Howard Kaikow | last post by:
I got bored today, so I decided to rewrite the code in KB article 316383 to decrease the number of object references. This resulted in a number of nested With ... End With. The original code had...
10
by: John Salerno | last post by:
Here's a sentence from Learning Python: "Names not assigned a value in the function definition are assumed to be enclosing scope locals (in an enclosing def), globals (in the enclosing module's...
5
by: Sandra-24 | last post by:
Is there a way in python to add the items of a dictionary to the local function scope? i.e. var_foo = dict. I don't know how many items are in this dictionary, or what they are until runtime. ...
5
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Could someone give me a simple example of nested scope in C#, please? I've searched Google for this but have not come up with anything that makes it clear. I am looking at the ECMA guide and...
3
by: beiercai | last post by:
Hi Experts, I'm new to JavaScript and have some problem to understand variable scope thing. I declared two variables, xHTTP and xmlDoc as a global variable so I suppose it is accessible throughout...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
0
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...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.