|
-
May 28th, 2012, 03:31 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Return XML values sorted
Hi,
I havew a smal xml file which looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<fv>
<flv url="http://www.mysite1.com">Windows</flv>
<flv url="http://www.mysite2.com">Happy</flv>
</fv>
I'm creating buttons in my app from the "innertext":
vb.net Code:
Dim myxml As XmlDocument = New XmlDocument()
myxml.Load(favoPath)
For Each el As XmlElement In myxml.DocumentElement.ChildNodes
Dim itm As New ButtonItem(el.InnerText, el.InnerText)
itm.Tag = el.GetAttribute("url")
'etc...
This all works fine, all the buttons are added according the xml. I would like to know how to sort the "innertext" so the buttons are alphabetically added.
[Happy]
[Windows]
Thanks in advance.
-
May 28th, 2012, 05:02 AM
#2
Re: Return XML values sorted
If you're using VS2008 or later then use XDocument and XElement instead of the older XmlDocument and XmlElement classes and use Linq to get a sorted list.
Code:
'Dim myxml As XDocument = XDocument.Load(favoPath)
Dim myxml As XDocument = <?xml version="1.0" encoding="utf-8"?>
<fv>
<flv url="http://www.mysite8.com">Windows</flv>
<flv url="http://www.mysite3.com">Happy</flv>
<flv url="http://www.mysite1.com">Sorry</flv>
<flv url="http://www.mysite2.com">Killer</flv>
</fv>
Dim elements = myxml.Root...<flv>.OrderBy(Function(el) el.Value)
For Each el In elements
'Create your buttons here
Next
-
May 28th, 2012, 05:31 AM
#3
Thread Starter
PowerPoster
Re: Return XML values sorted
That does work. Thank you for that. Unfortunately I have to rewrite a lot of code, cause I'm also adding and deleting. Will let you know.
-
May 28th, 2012, 07:04 AM
#4
Thread Starter
PowerPoster
Re: Return XML values sorted
+REP. Thanks.
There is a small issue I have left: When I get the url attribute:
mgsbox(el.attribute("url").tostring)
it returns exactly:
url="www.thewebsite.com"
I only want the www.thewebsite.com. Any suggestions?
EDIT: Foolish me!!! It should be "("url").Value"
Last edited by Radjesh Klauke; May 28th, 2012 at 07:09 AM.
-
May 28th, 2012, 10:39 AM
#5
Re: [RESOLVED] Return XML values sorted
You can also use the axis properties in VB to access the attributes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|