Solved

Loop through xml elements

Posted on 2010-11-08
4
1,619 Views
Last Modified: 2012-05-10
My xml is below.  I want to loop through my xml and create a new map element based on the values in that RetailTowns node


For Each XElement In myXML.Elements
            Dim retailPushpin As New Pushpin
            retailPushpin.Name = myXML.Elements("Town").Value
            retailPushpin.Location = New Location(myXML.Elements("Longitude").Value, myXML.Elements("Latitude").Value)
            retailPushpin.Content = myXML.Elements("Town").Value
            retailPushpin.Visibility = Visibility.Visible

            retailTowns.Children.Add(retailPushpin)
        Next

Open in new window

RetailTowns.xml
0
Comment
Question by:DotNetNooby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
kolakanuru1 earned 500 total points
ID: 34087989
       For Each XElement As XmlElement In myXML.GetElementsByTagName("RetailTowns Query")
            Dim Town As String = XElement.SelectSingleNode("Town").InnerText
            Dim Longitude As String = XElement.SelectSingleNode("Longitude").InnerText
        Next
0
 

Author Comment

by:DotNetNooby
ID: 34088049
I'm not able to access the As XML Element or myXML.GetElementsByTagName
    Sub LoadRetailTowns()
        Dim client As WebClient = New WebClient()
        AddHandler client.OpenReadCompleted, AddressOf OpenReadCallback
        Dim uri As Uri = New Uri("RetailTowns.XML", UriKind.Relative)
        client.OpenReadAsync(uri)
    End Sub
    Sub OpenReadCallback(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)
        Dim myXML As XElement = XElement.Load(XmlReader.Create(e.Result))

        For Each XElement In myXML.Elements
            Dim retailPushpin As New Pushpin
            retailPushpin.Name = myXML.Elements("Town").Value
            retailPushpin.Location = New Location(myXML.Elements("Longitude").Value, myXML.Elements("Latitude").Value)
            retailPushpin.Content = myXML.Elements("Town").Value
        Next

    End Sub

Open in new window

0
 
LVL 3

Assisted Solution

by:kolakanuru1
kolakanuru1 earned 500 total points
ID: 34088122
       Dim myXML As XmlDocument = New XmlDocument()
        myXML.Load(FileName)
        For Each XElement As XmlElement In myXML.GetElementsByTagName("RetailTowns Query")
            Dim Town As String = XElement.SelectSingleNode("Town").InnerText
            Dim Longitude As String = XElement.SelectSingleNode("Longitude").InnerText
        Next



Replace the filename with filepath of the xmldocument. This is working fine in my test.
0
 

Author Closing Comment

by:DotNetNooby
ID: 34103234
solved
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question