I've an xml parser that parses the attached "testXML.xml" file absolutely correctly. My question is i might have to parse the "[email protected] xml" file and won't it make my parser extremely complicated since, I have to keep track of where the contacts of a particular group end. I'm storing the contents in a treeview with the group names being the parent and the contacts being the children.
So I wanted to get a feedback about parsing the "[email protected] xml" file or is it easy to do so.
Here's the code for parser and i've attached the two xml files:
VB Code:
Private Sub LoadXMLNode()
Dim xmlDoc As DOMDocument30
Dim intCounter As Integer
Set xmlDoc = New MSXML2.DOMDocument30
xmlDoc.Load ("C:\testXML.xml")
Call RecurseChildNodes(xmlDoc, xmlDoc.childNodes)
Set xmlDoc = Nothing
End Sub
Private Sub RecurseChildNodes(xmlDoc As MSXML2.DOMDocument30, childNode As IXMLDOMNodeList)
Dim CurrChildNode As IXMLDOMNodeList
Dim intNodeCounter As Integer
Dim Name As String
Dim childName As String
Dim thisNode As Node
Dim ctr As Integer
Dim childNum As Integer
ctr = 0
Set CurrChildNode = childNode
For intNodeCounter = 0 To CurrChildNode.Length - 1
If CurrChildNode.Length > 0 Then
Set childNode = CurrChildNode.Item(intNodeCounter).childNodes
If childNode.Length > 0 Then
RecurseChildNodes xmlDoc, childNode
If CurrChildNode.Item(intNodeCounter).nodeName = "Group" Then
Name = CurrChildNode.Item(intNodeCounter).Attributes.getNamedItem("type").nodeValue
Set thisNode = TreeView1.Nodes.Add(, , Name, Name)
You don't need to use recursion to build your treeview. Here's code for the first file that does it without. (BTW, you should probably download and use MSXML4 rather than 3).
VB Code:
Private Sub WithOutRecursion(xmlDoc As MSXML2.DOMDocument30)
Dim oxmlNodeList As IXMLDOMNodeList
Dim intNodeCounter As Integer
Dim Name As String
Dim childName As String
Dim thisNode As Node
Dim ctr As Integer
Dim childNum As Integer
Set oxmlNodeList = xmlDoc.documentElement.selectNodes("Group")
For intNodeCounter = 0 To oxmlNodeList.length - 1
Name = oxmlNodeList.Item(intNodeCounter).Attributes.getNamedItem("type").nodeValue
Set thisNode = TreeView1.Nodes.Add(, , Name, Name)
For ctr = 0 To oxmlNodeList(intNodeCounter).childNodes.length - 1
thanxs soooo much, i waz just wondering what i should do for the second xml if i get error when adding same root in the treeview, thanks a lot for resolving it