XML Help...PLEASE!!!
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
7 posts
Page 1 of 1
i am having some trouble trying to figure this one out. If you can help, please do.
my XML FILE
i cant do a regular loop without the ID="" attribute but i can edit the listing. i have no way of searching the xml for the correct record to update. ei: the ID="" attribute.
any ideas?
scottie1972
my XML FILE
Code: Select all
my Load Function
<?xml version="1.0" encoding="utf-8"?>
<enemies>
<enemie ID="1">
<sector>100</sector>
<playerName>Billy Bob</playerName>
<level>1</level>
<coords>00000,000</coords>
<tactic>none</tactic>
</enemie>
<enemie ID="2">
<sector>200</sector>
<playerName>Billy Bob</playerName>
<level>2</level>
<coords>00000,000</coords>
<tactic>none</tactic>
</enemie>
<enemie ID="3">
<sector>300</sector>
<playerName>Billy Bob</playerName>
<level>3</level>
<coords>00000,000</coords>
<tactic>none</tactic>
</enemie>
</enemies>
Code: Select all
what i need todo is loop through all the nodes in the XML and load the results into a listview. so later i can click on a listing and edit that node/entry.Dim file As String = Application.StartupPath + "\data\enemies.xml"
Dim xd As New XmlDocument()
xd.Load(file)
For Each IDNode As XmlNode In xd.SelectNodes("//enemies/enemie")
If IDNode.HasChildNodes = True Then
Dim str(6) As String
Dim itm As ListViewItem
str(0) = IDNode.ChildNodes(0).InnerText
str(1) = IDNode.ChildNodes(1).InnerText
str(2) = IDNode.ChildNodes(2).InnerText
str(3) = IDNode.ChildNodes(3).InnerText
str(4) = IDNode.ChildNodes(4).InnerText
'str(5) = IDNode.ChildNodes(5).InnerText
itm = New ListViewItem(str)
itm.Tag = ""
ListView1.Items.Add(itm)
End If
Next
i cant do a regular loop without the ID="" attribute but i can edit the listing. i have no way of searching the xml for the correct record to update. ei: the ID="" attribute.
any ideas?
scottie1972
Hello Scottie,
Im not 100% sure what you want to do and you know im no expert in XML lol.
If you mean you want to get the ID attribute of each enemy node then you could use:
Im not 100% sure what you want to do and you know im no expert in XML lol.
If you mean you want to get the ID attribute of each enemy node then you could use:
Code: Select all
That would show the ID attribute of each node. Is that what you meant? :?IDNode.Attributes.ItemOf(0).Value
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
what i need todo is loop throught all the entries and placer them in a listview control. then be able to edit/update/save each entry by its ID="?"
attribute.
attribute.
Code: Select all
;)Dim enemieID as integer
Using reader As XmlReader = XmlReader.Create(Application.StartupPath + "\data\enemies.xml")
While reader.Read()
If reader.IsStartElement() Then
If reader.Name = "enemie" Then
enemieID = reader("ID")
End If
End If
End While
End Using
Kieken72 wrote:Code: Select all;)Dim enemieID as integer Using reader As XmlReader = XmlReader.Create(Application.StartupPath + "\data\enemies.xml") While reader.Read() If reader.IsStartElement() Then If reader.Name = "enemie" Then enemieID = reader("ID") End If End If End While End Using
I LOVE SIMPLE CODE!
Thanks Kieken72, awesome!!!
You could also save each XML node in the ListViewItem's tag property to improve performance
please lock this topic if its solved
please lock this topic if its solved
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Scottie1972 wrote:Enjoying you like itKieken72 wrote:Code: Select all;)Dim enemieID as integer Using reader As XmlReader = XmlReader.Create(Application.StartupPath + "\data\enemies.xml") While reader.Read() If reader.IsStartElement() Then If reader.Name = "enemie" Then enemieID = reader("ID") End If End If End While End Using
I LOVE SIMPLE CODE!
Thanks Kieken72, awesome!!!
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023