Iterating through XML to add to combo box? 
Author Message
 Iterating through XML to add to combo box?

Are there any good code examples anywhere on the net that describe the
process needed to iterate through an xml file, adding the main elements
(element="") to a combobox, or the like?
--
David Wier
http://www.*-*-*.com/
http://www.*-*-*.com/


Mon, 26 Jul 2004 14:08:56 GMT  
 Iterating through XML to add to combo box?

Quote:
> Are there any good code examples anywhere on the net that describe the
> process needed to iterate through an xml file, adding the main elements
> (element="") to a combobox, or the like?

To add the following xml to a combobox,
with the name-tag in the list, and the
id-tag in the itemdata property...
Save the xml below in a file:

'------------- Items.xml------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
  <item>
    <id>123</id>
    <name>Item 1</name>
  </item>
  <item>
    <id>1</id>
    <name>Dag Sunde</name>
  </item>
  <item>
    <id>555</id>
    <name>Checkpoint Charlie</name>
  </item>
  <item>
    <id>7</id>
    <name>Jalla, Jalla</name>
  </item>
</root>
'-----------End Items.xml------------

Add a combobox, a Label and a commandbutton to a form,
Add MsXML 3.0 in Project --> References.
and put in the following code:
Private Sub Combo1_Click()

    Label1 = "Tag <id> = " & Combo1.ItemData(Combo1.ListIndex)

End Sub

Private Sub Command1_Click()

    Dim oDOM As MSXML2.DOMDocument
    Set oDOM = New MSXML2.DOMDocument

    ' Get the xml from URL into the Document Object Model(DOM)
    If Not oDOM.Load("C:\Z\Items.xml") Then
        MsgBox (oDOM.parseError.reason)
    Else

        'Grab the root node (All processing is done from the root).
        Dim oRoot As MSXML2.IXMLDOMNode
        Set oRoot = oDOM.documentElement

        ' Retrieve a list of <item> nodes
        Dim oItems As MSXML2.IXMLDOMNodeList
        Set oItems = oRoot.selectNodes("item")

        ' and iterate thru them, extracting the child
        ' elements <id> and <name> in the process
        Dim oItem As MSXML2.IXMLDOMNode
        For Each oItem In oItems
            Combo1.AddItem oItem.selectSingleNode("name").Text
            Combo1.ItemData(Combo1.NewIndex) =
oItem.selectSingleNode("id").Text
        Next oItem
    End If

    Set oItem = Nothing
    Set oItems = Nothing
    Set oRoot = Nothing
    Set oDOM = Nothing

End Sub

--
Dag.



Mon, 26 Jul 2004 16:37:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how add columns to a combo box in vb like access combos

2. Adding to a combo box or text box through the keyboard

3. adding to a combo box or list box

4. Binding XML to 2 combo boxes

5. binding XML to Combo Box

6. Read XML elements into Combo Box

7. Read XML elements into a Combo Box

8. Read XML elements into Combo Box

9. enter data in a combo box based on value from another combo box

10. Limit subform combo box by selection in parent combo box

11. Want Access combo box to filter rowsource of another combo box

12. Populating a combo box from another combo box

 

 
Powered by phpBB® Forum Software