need the title 005
<rom name="5092.u1" these 5092.u1
Code:
Private Sub Command5_Click()
Dim i As Integer
Set Me.TreeView1.ImageList = Me.ImageList1
For i = 1 To 5
TreeView1.Nodes.Add , , "ROOT" & i, "Root Item " & i, 1
Next
'
' Now add some children
'
For i = 1 To 5
With TreeView1.Nodes
.Add "ROOT1", tvwChild, "ROOT1CHILD" & i, "Child Item " & i, 2
.Add "ROOT2", tvwChild, "ROOT2CHILD" & i, "Child Item " & i, 2
.Add "ROOT3", tvwChild, "ROOT3CHILD" & i, "Child Item " & i, 2
.Add "ROOT4", tvwChild, "ROOT4CHILD" & i, "Child Item " & i, 2
.Add "ROOT5", tvwChild, "ROOT5CHILD" & i, "Child Item " & i, 2
End With
Next
End Sub
Last edited by doberman2002; Oct 14th, 2019 at 05:34 PM.
I can't tell how many of these questions are headed down the rabbit hole of trying to use controls in place of data structures. There doesn't seem to be any reason to display the information and there isn't any user interaction with it.
Your question is regarding a listview, yet your sample code is for a treeveiw.
If you spend some time learning how to use DOM to parse XML data, I think you could dramatically improve your ability to extract the data easier
Code:
Private Sub Command2_Click()
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim x As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game[rom[@name='" & "rom name" & "']]")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
' Debug.Print xmlElement.getAttribute("name")
List1.AddItem xmlElement.getAttribute("name")
Next
End Sub
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim x As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game[rom[@name='03k_sb-8.bin']]")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
' Debug.Print xmlElement.getAttribute("name")
List1.AddItem xmlElement.getAttribute("name")
Next
am trying to learn how this works kind of stuck, can you give me a little instruction how to extract them string this seems interesting been doing it for one hour still no go.
Using your exact code and the file you posted in #1 above, I get 3 games: 1942, 1942a, 1942b
Whenever something is not working, you should explain in detail what you are expecting and any errors you are getting. If you are using On Error Resume Next, then don't do that -- you'll hide errors that could be telling you what is wrong.
Insomnia is just a byproduct of, "It can't be done"
Using your exact code and the file you posted in #1 above, I get 3 games: 1942, 1942a, 1942b
Whenever something is not working, you should explain in detail what you are expecting and any errors you are getting. If you are using On Error Resume Next, then don't do that -- you'll hide errors that could be telling you what is wrong.
am trying to learn more about how to use this in depth.
for the sake of learning i want to extract all <rom name="41_09.rom"41_09.rom strings in red area and load it up in treeview with parant rom title?.
once i get the hang of it i can step forward test more my self am just stuck at this
i just want to learn how to pull them data out using xml method,xml seems very fast and i like it am just learning still.
ok update i finally messed about did this and extracted all titles
Code:
Private Sub Command4_Click()
List1.Clear
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim x As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
' Debug.Print xmlElement.getAttribute("name")
List1.AddItem xmlElement.getAttribute("name") '& ".zip"
Next
End Sub
Last edited by doberman2002; Oct 15th, 2019 at 03:24 PM.
the [ ] above are like parentheses
game :: only look at 1st child elements where its element is <game [optional attributes]>
rom :: only look at child elements of <game> where child name is <rom [optional attributes]>
@name :: only look for attributes of <game><rom> where attribute name is "name" and value is: 03k_sb-8.bin
the @ symbol means: attribute
so, only these elements will be returned, if any
<game [optional attributes]> having child elements like: <rom name="03k_sb-8.bin" [other optional attributes]>
Look at sites that have tutorials for: XPath queries
Insomnia is just a byproduct of, "It can't be done"
the [ ] above are like parentheses
game :: only look at 1st child elements where its element is <game [optional attributes]>
rom :: only look at child elements of <game> where child name is <rom [optional attributes]>
@name :: only look for attributes of <game><rom> where attribute name is "name" and value is: 03k_sb-8.bin
the @ symbol means: attribute
so, only these elements will be returned, if any
<game [optional attributes]> having child elements like: <rom name="03k_sb-8.bin" [other optional attributes]>
Look at sites that have tutorials for: XPath queries
ok update i finally messed about did this and extracted all titles
Code:
Private Sub Command4_Click()
List1.Clear
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim x As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
' Debug.Print xmlElement.getAttribute("name")
List1.AddItem xmlElement.getAttribute("name") '& ".zip"
Next
End Sub
how you will tell the code to extract that rom name= only
ok this also pulls names again
Code:
Private Sub Command5_Click()
List1.Clear
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim x As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game[rom[@rom]]")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
List1.AddItem xmlElement.getAttribute("name")
Next
End Sub
am trying to get to extract the rom name secion trying.
Code:
Set xmlNodes = myXMLfile.documentElement.selectNodes("rom[@name]")
nothing?
Last edited by doberman2002; Oct 15th, 2019 at 03:42 PM.
Private Sub Command4_Click()
List1.Clear
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim xmlROMs As IXMLDOMNodeList
Dim x As Long, r As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
Debug.Print xmlElement.getAttribute("name")
Set xmlROMs = xmlNodes(x).selectNodes("rom")
For r = 0 To xmlROMs.length - 1
Set xmlElement = xmlROMs(r)
Debug.Print vbTab; xmlElement.getAttribute("name")
Next
Next
End Sub
Insomnia is just a byproduct of, "It can't be done"
Private Sub Command4_Click()
List1.Clear
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim xmlROMs As IXMLDOMNodeList
Dim x As Long, r As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
Debug.Print xmlElement.getAttribute("name")
Set xmlROMs = xmlNodes(x).selectNodes("rom")
For r = 0 To xmlROMs.length - 1
Set xmlElement = xmlROMs(r)
Debug.Print vbTab; xmlElement.getAttribute("name")
Next
Next
End Sub
thanks lavlope am not going to close this thread as i will be doing more test to learn from your code this is incredible.
the way you done it is way different to code i posted.
let me copy and paste binary code from your brain to mine?
Last edited by doberman2002; Oct 15th, 2019 at 03:48 PM.
Private Sub Command8_Click()
Dim i As Integer
Set Me.TreeView1.ImageList = Me.ImageList1
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim x As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
TreeView1.Nodes.Add , , "ROOT" & x, xmlElement.getAttribute("name"), 1
Next
End Sub
child code
Code:
Private Sub Command14_Click()
Set Me.TreeView1.ImageList = Me.ImageList1
Dim myXMLfile As DOMDocument60
Dim xmlElement As IXMLDOMElement
Dim xmlNodes As IXMLDOMNodeList
Dim xmlROMs As IXMLDOMNodeList
Dim x As Long, r As Long
Set myXMLfile = New DOMDocument60
myXMLfile.setProperty "ProhibitDTD", False
myXMLfile.validateOnParse = False
myXMLfile.Load "C:\Users\parry\Desktop\listview rom\MAME 0.37b5.dat"
Set xmlNodes = myXMLfile.documentElement.selectNodes("game")
For x = 0 To xmlNodes.length - 1
Set xmlElement = xmlNodes(x)
Debug.Print xmlElement.getAttribute("name")
Set xmlROMs = xmlNodes(x).selectNodes("rom")
For r = 0 To xmlROMs.length - 1
Set xmlElement = xmlROMs(r)
' List1.AddItem xmlElement.getAttribute("name")
TreeView1.Nodes.Add "ROOT" & r, tvwChild, "ROOT1CHILD" & r, xmlElement.getAttribute("name"), 2
Next
Next
End Sub
key is not unique in collection,how do i add each rom name as child belonging to its parent title in treeview
Last edited by doberman2002; Oct 15th, 2019 at 06:26 PM.
Don't both ListView and TreeView have a 32767 node limit anyway?
I'd use SAX2 and the MSHFlexGrid for this sort of thing. Assuming of course that it makes sense to list everything, which I doubt.
XML DOMs are pretty bloated to begin with and don't do that well for large documents. Then when you add the scripter's tool XPath to the mix... things gear down pretty quickly to a crawl.
There's a good reason we have SAX2, and even the DOM uses it internally to do its parsing.