XML Node Problem

x3816

New member
Joined
Jan 1, 2008
Messages
2
Programming Experience
Beginner
hello everybody i have a small problem and i hope someone knows how i can solve this problem.
i want to but the content of an xml file in to a listview.

thats my xml file
HTML:
<?xml version="1.0"?>
<bbapi version="1.0.0">
    <teamdata>
        <userName>killersush</userName>
        <teamID>41726</teamID>
        <teamName>Team Rapunzel</teamName>
    </teamdata>
    <roster retrieved="2007-12-28 21:28:20"> <!-- time is CET -->
     
           <player>
               <id>802727</id>
               <name>
                   <firstName>Filippo</firstName>
                   <lastName>Fuscioni</lastName>
               </name>
               <country>10</country>
               <age>18</age>
               <height>77</height>
               <DMI>30000</DMI>
               <injury>0</injury>
               <jersey>999</jersey>
               <salary>3458</salary>
               <ratings>               
                   <practice>8</practice>
                   <experience>3</experience>
                   <jumpShot>8</jumpShot>
                   <range>7</range>
                   <outsideDef>4</outsideDef>
                   <handling>4</handling>
                   <driving>6</driving>
                   <passing>2</passing>
                   <insideShot>5</insideShot>
                   <insideDef>4</insideDef>
                   <rebound>2</rebound>
                   <block>6</block>
                   <stamina>5</stamina>
                   <freeThrow>5</freeThrow>
               </ratings>
               
           </player>   
      
           <player>
               <id>2215564</id>
               <name>
                   <firstName>Alfonz</firstName>
                   <lastName>Faragó</lastName>
               </name>
               <country>48</country>
               <age>25</age>
               <height>72</height>
               <DMI>3800</DMI>
               <injury>0</injury>
               <jersey>999</jersey>
               <salary>2743</salary>
               <ratings>               
                   <practice>4</practice>
                   <experience>2</experience>
                   <jumpShot>6</jumpShot>
                   <range>6</range>
                   <outsideDef>1</outsideDef>
                   <handling>6</handling>
                   <driving>5</driving>
                   <passing>6</passing>
                   <insideShot>2</insideShot>
                   <insideDef>4</insideDef>
                   <rebound>4</rebound>
                   <block>4</block>
                   <stamina>5</stamina>
                   <freeThrow>4</freeThrow>
               </ratings>
               
           </player>
and this is the script


VB.NET:
        Dim doc As New XmlDocument
        doc.Load("xmlfile.xml")
        Dim xnlIds As XmlNodeList = doc.SelectNodes("//player")
        If ((Not xnlIds Is Nothing) AndAlso (xnlIds.Count > 0)) Then

            Dim xnId As XmlNode

            For Each xnId In xnlIds
                playerview.Items.Add(xnId.InnerText)
            Next
        End If

        playerview.View = View.Details
the file is working, i can read the content from the xml file and i can but it into the listview but only in one long string.
no i want too show every element like id / age / country in an extra column.
how can i use xnID to get the elements one by one ?
if i try to use SelectNodes with xnID i get an error message.
if i try to use SelectSingleNode with xnID i get allwas just the first element no matter how offen the for each loop is going.
i didnt find the solution, i tryed allready in a few german forum but nobody could help me.

so if someone knows to handle please give me a hint.

thx
x
 
Last edited by a moderator:
VB.NET:
Dim doc As New XmlDocument
doc.Load("xmlfile.xml")
Dim item As ListViewItem
For Each player As XmlNode In doc.SelectNodes("//player")
    item = playerview.Items.Add(player.SelectSingleNode("id").InnerText)
    item.SubItems.Add(player.SelectSingleNode("name/firstName").InnerText)
    item.SubItems.Add(player.SelectSingleNode("name/lastName").InnerText)
Next
 
Back
Top