|
-
Apr 8th, 2014, 04:48 PM
#1
Thread Starter
Member
[RESOLVED] XML Parsing and counting
good day all I have a little issue with reading xml which i have not done before
Im trying to read an xml and load it into a list view(easy and done)
what i want to do is count wheather a category field says "cms" or says "php" thats it. what im trying to do is with the list view add the category once with the the count. looking like
application
------cms(15)
------php(5)
------blog(25)
here is a portion of my xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<product>
<application>
<packageid>PHPnuke</packageid>
<packageType>CMS</packageType>
<version>[1.0.40959.2]</version>
<feedURL>file://%ProgramFiles%\test\templates\</feedURL>
<image>http://phpnuke.org/images/logo.png</image>
</application>
<application>
<packageid>PHPCurcuit</packageid>
<packageType>blog</packageType>
<version>[1.0.40959.2]</version>
<feedURL>file://%ProgramFiles%\test\templates\</feedURL>
<image>http://phpnuke.org/images/logo.png</image>
</application>
<application>
<packageid>PHPCurcuit</packageid>
<packageType>php</packageType>
<version>[1.0.40959.2]</version>
<feedURL>file://%ProgramFiles%\test\templates\t</feedURL>
<image>http://phpnuke.org/images/logo.png</image>
</application>
</product>
what i have so far
Code:
Dim lv As ListViewItem
Dim xd As XDocument = XDocument.Load(pathToMain & "Recources\SitesGallery.xml")
Dim appinfo = From info In xd.Descendants("application") _
Select New With _
{ _
.packageid = info.Element("packageid").Value, _
.packageType = info.Element("packageType").Value, _
.version = info.Element("version").Value, _
.feedURL = info.Element("feedURL").Value, _
.image = info.Element("image").Value _
}
lv = New ListViewItem()
lv.Text = "All(" & xd.Elements("application").Nodes.Count & ")"
Me.LVCategories.Items.Add(lv)
For Each node In appinfo
lv = New ListViewItem()
lv.Text = node.category
Me.LVCategories.Items.Add(lv)
Next
please help if you can
thanks in advance
Were there is code there is a way...
-
Apr 9th, 2014, 11:15 AM
#2
Thread Starter
Member
Re: XML Parsing and counting
yeah no one aswers i do it myself this is now resolved
Code:
'read in xml for use
Dim xd As XDocument = XDocument.Load(pathToMain & "Recources\SitesGallery.xml")
Dim appinfo = From info In xd.Descendants("application") _
Select New With _
{ _
.packageid = info.Element("packageid").Value, _
.packageType = info.Element("packageType").Value, _
.version = info.Element("version").Value, _
.feedURL = info.Element("feedURL").Value, _
.image = info.Element("image").Value _
}
Dim group = appinfo.GroupBy(Function(value) value.packageType)
Dim lv As ListViewItem
Dim itm As ListViewItem
lv = New ListViewItem()
lv.Text = "All"
Me.LVCategories.Items.Add(lv)
With LVCategories
For Each node In appinfo
itm = .FindItemWithText(node.packageType, True, 0, True)
If itm Is Nothing Then
lv = New ListViewItem()
For Each grp In group
If grp(0).packageType = node.packageType Then
lv.Text = node.packageType & " (" & grp.Count & ")"
End If
Next
Me.LVCategories.Items.Add(lv)
End If
Next
End With
LVCategories.Items.Item(0).Selected = True
lv = Nothing
itm = Nothing
you can take that to the bank ...
Were there is code there is a way...
Tags for this Thread
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
|