-
VB6 and XML
Hi all,
Have a problem reading and searching XML with VB6.
First of all, I have an XML file that goes roughly like this:
Code:
<calltypes>
<calltype>
<category>Undetermined</category>
<type>000 Type of incident undetermined</type>
<type>008 Type of action taken not reported due to industrial action</type>
</calltype>
<calltype>
<category>Fire and Explosions</category>
<type>100 Fire or Explosion; insuff info to classify</type>
<type>109 Fire or Explosion not classified</type>
</calltype>
Now what I want to do is display the 'category' contents in one combo box (I've got that going fine), but then once I've selected a category, it populates a second combo box with the 'type' entries from that node.
So, as an example using the XML above, in the first combo I select "Fire and Explosions". Then, the second combo would have the entries "100 Fire or Explosion; insuff info to classify" and "109 Fire or Explosion not classified" in it.
As I mentioned, I have the first combo box reading from the XML file with no problems at all. Now I just need to get it reading the 'types' according to the selection.
I'm using VB6 Enterprise, MSXML 5 is doing the actual dirty work reading from the XML file.
My questions are:
- Is the structure of the XML file suitable?
- If so, how would I grab the 'type' fields depending on which 'category' is selected?
Happy to post up any code or information as required. When we're done I'll be sure to post the source code for anyone else who needs help.
Thanks for your help!
-
I recommend that you change the file structure so that the <type> elements are children of the associated <category>:
Code:
<calltypes>
<calltype>
<category id="Undetermined">
<type>000 Type of incident undetermined</type>
<type>008 Type of action taken not reported due to industrial action</type>
</category>
</calltype>
<calltype>
<category id="Fire and Explosions">
<type>100 Fire or Explosion; insuff info to classify</type>
<type>109 Fire or Explosion not classified</type>
</category>
</calltype>
</calltypes>
To populate the Category combo, do this:
Code:
Dim doc As DOMDocument30
Dim nodes As IXMLDOMNodeList
Dim node As IXMLDOMNode
Set doc = New DOMDocument30
doc.Load "d:\path\calltypes.xml"
Set nodes = doc.selectNodes("//category")
For Each node In nodes
cboCategory.AddItem node.Attributes.getNamedItem("id").Text
Next
Then, given the text of the selected category, populate the second combo like this:
Code:
Set node = doc.selectSingleNode("//category[@id='" & cboCategory.Text & "']")
Set nodes = node.childNodes
For Each node In nodes
cboType.AddItem node.Text
Next
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Thanks for your help Phil, it's truly appreciated.
I altered the XML file to suit your recommendation, and used the code you posted, but unfortunately still without luck.
Code:
Set doc = New DOMDocument30
doc.Load App.Path & "\calltypes.xml"
Set nodes = doc.selectNodes("//category")
For Each node In nodes
cboCategory.AddItem node.Attributes.getNamedItem("id").Text
Next
When populating the Category combo using the above code, on line 4 above it appears not to find any nodes, because it skips the AddItem line and goes right on past Next.
Any thoughts on that one?
Also, looking at the XML file, would you agree that the <calltype> level is now redundant?
Thanks again for your valuable assistance.
Cam
-
Please post your XML file. The code should work (I tested it before I posted).
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Ah ha! That's done it. I ran the XML file through a checker (should have done that before) and turned out I had a double quotation mark 50 lines down that killed it.
Works perfectly now, thanks very much for your help!
Cam
Similar Threads
-
By eranfox in forum VB Classic
Replies: 5
Last Post: 08-09-2007, 07:18 AM
-
Replies: 0
Last Post: 04-25-2007, 06:54 PM
-
Replies: 0
Last Post: 12-21-2005, 08:53 PM
-
By smithg22 in forum VB Classic
Replies: 9
Last Post: 04-12-2005, 06:23 PM
-
By Tony Fountain in forum XML
Replies: 3
Last Post: 06-19-2000, 09:58 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks