Hi all. i have the following remote rss xml in rss.php I want to populate the xml data to vb6 listview. could any one show me how this can be done.Thanks
Note:The number of items in xml is dynamic not fixedrss.php
Re: How to populate listview with remote xml data?
This works.
I wrote it real fast though, hope it's what you were looking for.
Run the project and click 'Go'.
I put the code into a couple subs, so you can easily just put them and use them in your project.
There's probably an XML library or control you could reference that would be the 'proper' way to do it but I'm not sure so I wrote it with normal VB functions.
Re: How to populate listview with remote xml data?
Give this a try
Set a reference to the "Microsoft XML, v3.0" or what ever version you have listed.
Code:
Private Sub Form_Load()
Dim objDoc As MSXML2.DOMDocument
Dim objNodelist As IXMLDOMNodeList
Dim objNode As IXMLDOMNode
Dim lvwItem As ListItem
'load the xml document
Set objDoc = New MSXML2.DOMDocument
objDoc.async = False
objDoc.Load "c:\playlist.xml"
'add all the song nodes into a nodelist
Set objNodelist = objDoc.selectNodes("//song")
'Set up the listview
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "Artist"
ListView1.ColumnHeaders.Add , , "Name"
ListView1.ColumnHeaders.Add , , "Image"
ListView1.ColumnHeaders.Add , , "Rating"
ListView1.ColumnHeaders.Add , , "Song ID"
ListView1.ColumnHeaders.Add , , "Total Votes"
'Loop through each song node and add to the list view
For Each objNode In objNodelist
Set lvwItem = ListView1.ListItems.Add(, , objNode.selectSingleNode("artist").Text)
lvwItem.SubItems(1) = objNode.selectSingleNode("name").Text
lvwItem.SubItems(2) = objNode.selectSingleNode("image").Text
lvwItem.SubItems(3) = objNode.selectSingleNode("rating").Text
lvwItem.SubItems(4) = objNode.selectSingleNode("songid").Text
lvwItem.SubItems(5) = objNode.selectSingleNode("totalvotes").Text
Next objNode
Set lvwItem = Nothing
Set objNodelist = Nothing
Set objDoc = Nothing
End Sub
Re: How to populate listview with remote xml data?
Thank you for both of you. Could you both tell me if the rss is located on remote server then how should i achive this task? The extention of the rss is php not xml so it might not work in the same way!!
Re: How to populate listview with remote xml data?
You can use the Inet (Microsoft Internet Transfer Control) to get the source of the PHP page.
I have a module that doesn't require the inet control but it's been giving me weird results lately so I'm not going to recommend it anymore.
After adding the inet control to your form you could do something like:
vb Code:
Dim strRSS As String
strRSS = Inet1.OpenURL("http://url.com/rss.php")
Then feed strRSS into mine or Mark's function. Note that if there is other code in the PHP page besides the RSS data, you'll need to extract the RSS data from it first.
But the sub I wrote (and I think Mark's too) should ignore any non-important data.
Re: How to populate listview with remote xml data?
Digirev thanks for your reply. I add the code in to onload event but it never loads the remotee xml for me!!! I used massage box to view the data and i saw all the data from remote xml but it never loads it to textbox!!
1 Code:
Private Sub Form_Load()
Dim Text1 As String
Text1 = Inet1.OpenURL("http://localhost/rss.php")
MsgBox " " + Text1
InitListView ListView1
End Sub
Furthermore, how to make sure my listview always has fresh data? My intention is to load that rss to listview and update it regulerly so i have updated data at all time.I be happy if i get in this regard too.Thanks
Last edited by tony007; May 3rd, 2007 at 10:04 AM.
Re: How to populate listview with remote xml data?
To clear the items in the ListView, put:
ListView.ListItems.Clear
Before calling the other subs that load the RSS into the ListView.
Also, I wouldn't declare a string with the name 'Text1' especially if you have a textbox on your form named Text1. Just declare it as something unique like:
Dim strRSS As String
And when adding one string to another, don't use the + sign, use &
Also, are you actually loading the RSS from your own computer? (localhost) or is that just an example?
It'd help to know what URL you're loading the RSS from so we can see it/test it.
Re: How to populate listview with remote xml data?
I was thinking that i need to feed it to textbox first(that is why i called it Text1) . I fixed that problem. Now the rss data loads in textbox but all the data in one big line and when i press the button nothing happens. I find it strange why all rss data shows in one line!!
I even used richtext box still didn't work!!
I also need some how to get fresh data at all time after making it work at start!!
Note:I am testing localy an example before i put things online.
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$server = "localhost"; // MySQL hostname
$username = "test"; // MySQL username
$password = "test"; // MySQL password
$dbname = "test"; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
// this is necessary, otherwise it won't work:
header('Content-type: application/xml');
// you need to return the error as xml as well
$res = mysql_query('SELECT * FROM songs ORDER by date') or die('<error>'.mysql_error().'</error>');
// display the root node of the xml, and start looping over the elements:
echo '<playlist>';
while($row = mysql_fetch_assoc($res)){
echo '<song>';
echo '<artist>'.$row['artist'].'</artist>';
echo '<name>'.$row['name'].'</name>';
echo '<image>'.$row['image'].'</image>';
echo '<rating>'.$row['rate'].'</rating>';
echo '<songid>'.$row['songid'].'</songid>';
echo '<totalvotes>'.$row['totvotes'].'</totalvotes>';
echo '</song>';
}
echo '</playlist>';
?>
Last edited by tony007; May 3rd, 2007 at 11:28 AM.
Re: How to populate listview with remote xml data?
It's showing it all on one line because that is how your PHP script is outputting it. There are no line breaks in the PHP code's output (\n).
Also, don't store it in a TextBox first, it's not necessary. The TextBox is also limited to 64KB of data so if the RSS ever exceeds that then it will mess things up. Just use a string variable and do NOT name it Text1.
The code I gave you expects new lines after each tag. I assumed they were there because that is how you displayed it in your example.
Use Mark's code, it should work.
And change the one line to what he said in post #7.
Re: How to populate listview with remote xml data?
Originally Posted by MarkT
Do you have a listview on the page?
Mark thanks i added listview it got fixed.Since this rss feed data. Is there away that i make sure this listview has fresh data almost instantly?I have doen similer thing using ajax and javascript but not sure how to achive it in vb6.could you show me how this can done?
Re: How to populate listview with remote xml data?
Originally Posted by MarkT
The easy way to do it would be to place timer on the page and have it reload the data at set intervals.
I have this timer o reload webbrowser controle. But don't know how to update listview every few seconds using it.could you let me know how to get updated data for code you provided?Thanks
Re: How to populate listview with remote xml data?
If I understand you, this should reload the listview every 2 minutes
Code:
Option Explicit
Private Sub Form_Load()
'Set up the listview
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "Artist"
ListView1.ColumnHeaders.Add , , "Name"
ListView1.ColumnHeaders.Add , , "Image"
ListView1.ColumnHeaders.Add , , "Rating"
ListView1.ColumnHeaders.Add , , "Song ID"
ListView1.ColumnHeaders.Add , , "Total Votes"
PopulateListview
Timer1.Interval = 60000 ' <-- one minute
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static lngMin As Long
lngMin = lngMin + 1
'every 2nd timer tick reload the listview
If lngMin Mod 2 Then
PopulateListview
End If
End Sub
Private Sub PopulateListview()
Dim objDoc As MSXML2.DOMDocument
Dim objNodelist As IXMLDOMNodeList
Dim objNode As IXMLDOMNode
Dim lvwItem As ListItem
'load the xml document
Set objDoc = New MSXML2.DOMDocument
objDoc.async = False
objDoc.Load "http://localhost/rss.php"
'add all the song nodes into a nodelist
Set objNodelist = objDoc.selectNodes("//song")
'Clear the listview
ListView1.ListItems.Clear
'Loop through each song node and add to the list view
For Each objNode In objNodelist
Set lvwItem = ListView1.ListItems.Add(, , objNode.selectSingleNode("artist").Text)
lvwItem.SubItems(1) = objNode.selectSingleNode("name").Text
lvwItem.SubItems(2) = objNode.selectSingleNode("image").Text
lvwItem.SubItems(3) = objNode.selectSingleNode("rating").Text
lvwItem.SubItems(4) = objNode.selectSingleNode("songid").Text
lvwItem.SubItems(5) = objNode.selectSingleNode("totalvotes").Text
Next objNode
Set lvwItem = Nothing
Set objNodelist = Nothing
Set objDoc = Nothing
End Sub
Re: How to populate listview with remote xml data?
Mark i realy thank you for this usefull code. It is working.However,
is there a way to create another listview and populate it with initial data and each time compare the Name columns of both listviews and if they are diffrent update the second listview. I am thinking of some how hiding unessary refreshes since i keep loosing focouse on the form!!could you help me with a solution for this unncessary refreshes?
Furthermore, In the same project i added another timer that frequently checks a remote xml. What i want this new timer some how check if the rss feed is giving any result/data set out. If it gives data out i need for example reload webbrowser controle.If it doesn't give any data out i do nothing. (I don't need to output xml content)Could you show me how i can make such check using your code.Thanks
Note:The url to check for its xml data is like this:
'http://localhost//datastatus.php?sessionkey=b429632c627bcf6bd4840561690e3c49
1 Code:
Private Sub Form_Load()
'Set up the listview
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "Artist"
ListView1.ColumnHeaders.Add , , "Name"
ListView1.ColumnHeaders.Add , , "Image"
ListView1.ColumnHeaders.Add , , "Rating"
ListView1.ColumnHeaders.Add , , "Song ID"
ListView1.ColumnHeaders.Add , , "Total Votes"
PopulateListview
'Timer1.Interval = 60000 ' <-- one minute
Timer1.Interval = 7000 ' <-- 10 seconds
Timer1.Enabled = True
Timer2.Interval = 7000 ' <-- 10 seconds
Timer2.Enabled = True
End Sub
Private Sub Timer2_Timer()
Static lngMin As Long
lngMin = lngMin + 1
'every 2nd timer tick reload the listview
If lngMin Mod 2 Then
checkForNewData
End If
End Sub
Private Sub checkForNewData()
'Here i need to check for new data . If new data is avalible then
'reload the webbrowser.
'i need some how check if the following php code outputs any xml or not?
$server = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "root"; // MySQL password
$dbname = "db"; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
// this is necessary, otherwise it won't work:
header('Content-type: application/xml');
// you need to return the error as xml as well
$res = mysql_query("SELECT w,h FROM datastatus WHERE who_sessid ='$sessionkey' ") or die('<error>'.mysql_error().'</error>');
// display the root node of the xml, and start looping over the elements:
echo '<playlist>';
while($row = mysql_fetch_assoc($res)){
echo '<song>';
echo '<artist>'.$row['w'].'</artist>';
echo '<name>'.$row['h'].'</name>';
echo '</song>';
}
echo '</playlist>';
?>
Last edited by tony007; May 4th, 2007 at 08:55 PM.
Re: How to populate listview with remote xml data?
is there a way of doing this on powerpoint and having a feed on a slide show?
-----------------------------------------------
"The hall is rented,"
"the orchestra is engaged,"
"its now time to see if you can dance!"
Q, Q-Who, Star Trek The Next Generation
-----------------------------------------------
General Work day
-----------------------------------------------
DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle