Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: filling treeview from xml file, but only certain tags >Thread Next - Re: filling treeview from xml file, but only certain tags Re: filling treeview from xml file, but only certain tagsTo: NULL Date: 8/1/2008 4:18:00 PM
minimalniemand wrote:
> the XML file for the example can be found here: http://mad-scientists.co.uk/micha/example.xml
I don't program with classic VB so here is an example with VB.NET 2005:
Sub InitializeTree(ByVal treeView As TreeView, ByVal src As String)
Dim doc As New XmlDocument()
doc.Load(src)
AddNodes(treeView.Nodes, doc.DocumentElement.SelectNodes("*"))
End Sub
Sub AddNodes(ByVal treeNodes As TreeNodeCollection, ByVal xmlNodes
As XmlNodeList)
For Each childElem As XmlNode In xmlNodes
Select Case childElem.LocalName
Case "CLAUSE"
Dim treeNode As New
TreeNode(childElem.SelectSingleNode("OPTEXT").InnerText)
treeNodes.Add(treeNode)
AddNodes(treeNode.Nodes,
childElem.SelectNodes("ITEMS/*"))
Case "ITEM"
treeNodes.Add(New
TreeNode(childElem.SelectSingleNode("ITEXT").InnerText))
End Select
Next
End Sub
It is then called as
InitializeTree(TreeView1, "..\..\XMLFile1.xml")
where TreeView1 is the tree view you want add nodes to and the second
argument is a string with the path to the XML file.
I realize you are not using .NET but classic VB and MSXML so here are
some hints how to translate the .NET XML DOM properties and methods to
MSXML and classic VB:
1) use selectNodes instead of SelectNodes
2) use selectSingleNode instead of SelectSingleNode
3) use text instead of InnerText
4) use MSXML2.DOMDocument30 instead of XmlDocument
5) make sure you call
xmlDocument.setProperty "SelectionLanguage", "XPath"
on your MSXML DOM document before you use selectNodes/selectSingleNode
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
