</div> <div class="line">I'm trying to calculate the users current distance to each of those locations using the co-ordinates provided. While my function for that works, I don't know how to append the newly found distance into each respective tag in the XML
file.</div> <div class="line"></div> <div class="line">My Code - </div> <div class="line"></div> <div class="line">
Dim isoStorage As IsolatedStorageFile
isoStorage = IsolatedStorageFile.GetUserStoreForApplication
Dim isoReaderStream As IsolatedStorageFileStream
isoReaderStream = isoStorage.OpenFile("nearestBranches.xml", FileMode.Open)
Dim xEle As XElement = XElement.Load(isoReaderStream)
Dim vals = xEle.Descendants("Table1")
For Each emp In vals
templat = Convert.ToDouble(emp.Element("latitude").Value)
templon = Convert.ToDouble(emp.Element("longitude").Value)
tempdist = distanceCalc(lat, lon, templat, templon)
temsdist = tempdist.ToString("0.0")
Dim arg As clsBranchList = New clsBranchList()
xEle.Add(New XElement("distance", temsdist))
Console.WriteLine(xEle)
Next emp
isoReaderStream.Close()
Dim isoReaderStream2 As IsolatedStorageFileStream
isoReaderStream2 = isoStorage.OpenFile("nearestBranches.xml", FileMode.Open)
Dim xdoc As XDocument
xdoc = XDocument.Load(isoReaderStream2)
Dim _posts = From post In xdoc.Descendants("Table1")
Order By CStr(post.Element("branch_name"))
Select New clsBranchList With {
.idf = CInt(post.Element("id")),
.distancef = post.Element("distance"),
.country_codef = post.Element("country_code"),
.branch_codef = post.Element("branch_code"),
.branch_namef = post.Element("branch_name"),
.record_numberf = CInt(post.Element("record_number")),
.legal_namef = post.Element("legal_name"),
.company_namef = post.Element("company_name"),
.addressf = post.Element("address"),
.telephonef = post.Element("telephone"),
.faxf = post.Element("fax"),
.emailf = post.Element("email"),
.latitudef = post.Element("latitude"),
.longitudef = post.Element("longitude")
}
Dim _postslist = _posts.ToList()
Dim DataSource As List(Of AlphaKeyGroup(Of clsBranchList)) = AlphaKeyGroup(Of clsBranchList).CreateGroups(_postslist, System.Threading.Thread.CurrentThread.CurrentUICulture, Function(s As clsBranchList)
Return s.branch_namef
End Function, True)
lb_branch_list.ItemsSource = DataSource
isoReaderStream2.Close()
</div> <div class="line">Using xEle.Add() appends each distance at the end of the XML file. I need a way to append each <distance> value </distance> within each <table1> tag serially.</div>
Based on my understanding, you want to add <distance> node as <tabel1> node's child node.
I suggest that you can try the code below(in c#)
//load xml XElement ex = XElement.Load(Server.MapPath("fileName.xml")); //find all the table1 node
IEnumerable<XElement> nodes = from ele in ex.Elements("table1")
select ele;
//loop the table1 node,add the new element as its childnode
foreach (XElement xl in nodes) {
xl.Add(new XElement("xx", "xxx"));
}
ex.Save(Server.MapPath("fileName.xml"));
You can user the link below to convert c# to vb.net:
None
0 Points
1 Post
Writing Elements at Runtime to the XML file in VB.net
Sep 08, 2014 02:58 AM|sridoodla|LINK
My XML File is as follows -
<div class="line"> </div> <div class="line">I'm trying to calculate the users current distance to each of those locations using the co-ordinates provided. While my function for that works, I don't know how to append the newly found distance into each respective tag in the XML file.</div> <div class="line"></div> <div class="line">My Code - </div> <div class="line"></div> <div class="line"> </div> <div class="line">Using xEle.Add() appends each distance at the end of the XML file. I need a way to append each <distance> value </distance> within each <table1> tag serially.</div>linqToXml xml vb.net
All-Star
16806 Points
2777 Posts
Microsoft
Re: Writing Elements at Runtime to the XML file in VB.net
Sep 08, 2014 10:37 PM|Kevin Shen - MSFT|LINK
Hi sridoodla,
Thanks for your post here.
Based on my understanding, you want to add <distance> node as <tabel1> node's child node.
I suggest that you can try the code below(in c#)
You can user the link below to convert c# to vb.net:
http://converter.telerik.com/
You can refer to the link below about how to Manipulating XML in Visual Basic:
http://msdn.microsoft.com/en-us/library/bb385097.aspx
Best Regards,
Kevin Shen.
linqToXml xml vb.net