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 8:16:00 AM I had to rewrite it this way: Sub InitializeTree(ByVal src As String) xml.Load (src) xml.setProperty "SelectionLanguage", "XPath" Call AddNodes(Me!ocxTreeView.Nodes, xml.documentElement.selectNodes("*")) End Sub Sub AddNodes(ByVal treeNodes As Nodes, ByVal xmlNodes As MSXML2.IXMLDOMNodeList) For Each x1 In xmlNodes Select Case x1.tagName Case "CLAUSE" Dim treeNode As Node Set treeNode = treeNodes.Add(, , , x1.selectSingleNode("OPTEXT").Text) treeNodes.Add (treeNode) Call AddNodes(treeNode.Nodes, x1.selectNodes("ITEMS/*")) Case "ITEM" treeNodes.Add (treeNodes.Add(x1.selectSingleNode("ITEXT").Text)) End Select Next End Sub But its not yet working. The Nodes Property of treeNode does not exist in VB, what exactly is it? Is it a list of all children under treeNode? there aint such a collection I'm afraid On 1 Aug., 16:17, Martin Honnen <mahotr...@yahoo.de> wrote: > 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 | |||
|
