|
-
Dec 7th, 2003, 08:55 AM
#1
Thread Starter
Member
XML woes
I am trying to do something that should be simple I guess, but I just cannto get it to work and have no clue how to get it to work.. Most likely I am overlooking the most simple solution, but I just cannot find it.
Here's what I have:
I have a XML file in this format:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<FXGroup>
<monfolder src="E:\_NEWS_\_incoming\muzak\Top40"/>
<media src="E:\MP3\Top40\What's up - Who else.mp3" title ="What's up" artist ="Who else" _
bpm ="110.34" gain ="00.00" duration ="03:46" comment ="Ehhh.." Format ="1" bitrate ="192" _
year ="2003" id ="0001-02" pos ="1"/>
</FXGroup>
As you might understand there's more <media> tags.. What I want to do is to read all the media tags and put them in a listview.. I guess I would have to take the information in the tag apart myself but that's not the problem, the problem is getting the tag into an array.. without just reading the XML file line by line.. There must be a way to 'just' get each <media> tag until there are no more.. Confused?? so am I right now.. :^)
I can get this XML file into a datagrid easy enough, but I want to use a listview..
As I said I tried a number of approaches, but seem to be unable to get it to work.. But then again,like I said I am probably overlooking the simplest solution..
-
Dec 7th, 2003, 10:58 AM
#2
Hyperactive Member
Can't really tell if you tried this or not, but I'd do something like this:
VB Code:
Dim xml As New XmlDocument()
xml.Load("YourFile.xml")
Dim xmlMediaNodeList As XmlNodeList = xml.DocumentElement.SelectNodes("//media")
If Not xmlMediaNodeList Is Nothing Then
For Each xmlMediaNode As XmlNode In xmlMediaNodeList
'do something with the node...
Next
End If
-
Dec 7th, 2003, 12:30 PM
#3
Thread Starter
Member
Although I see whee you're going I a still stuck and have no idea how to get the information in the <media> node.. does anyone have any pointers to where I can read up on this?
-
Dec 7th, 2003, 01:28 PM
#4
Fanatic Member
you might want to look into the XmlTextReader also... this is assuming you only need to read the info, and not write to the file at this stage...
in that case, you'd loop through all the nodes... check the node.Name i think, and that would return Media for the <Media> tag....
then you would want to use GetAttribute("src") and that would give you E:\_NEWS_\_incoming\muzak\Top40... and do the rest for the other attributes...
i'll post a little example in a second here
-
Dec 7th, 2003, 01:40 PM
#5
Hyperactive Member
-
Dec 7th, 2003, 01:42 PM
#6
Fanatic Member
Ok, here should be an example for you to go off of....
sorry it's in c#, i didn't even realize where i was posting at the time of writing it... should be easy enough to understand though...
also don't quote me on the use of the ListViewItem.. i'm not even sure that's right.. i just wrote it off the top of my head... but here it goes:
VB Code:
ListViewItem newItem;
XmlTextReader xr = new XmlTextReader("C:\MyXmlFile.xml");
while (xr.Read())
{
if (xr.Name.Equals("Media")
{
newItem = new ListViewItem("");
newItem.SubItems.Add(xr.GetAttribute("src"));
newItem.SubItems.Add(xr.GetAttribute("title"));
newItem.SubItems.Add(xr.GetAttribute("bpm"0));
//etc. etc.. for all the other tags
listView1.Items.Add(newItem);
newItem = null;
}
}
xr.Close();
xr = null;
-
Dec 7th, 2003, 06:19 PM
#7
Thread Starter
Member
That worked perfectly for me!.. Luckily I am not so much a newbie anymore I cannot read another languege..
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
|