Results 1 to 2 of 2

Thread: XML Experts, pls Help...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217

    XML Experts, pls Help...

    I'm having some trouble with XML. In my application, I have a combo box populated with all of the Presentation_Name element's text added to the combo box. Now, when I select a presentation name from the combo box, another combobox right below the first one, gets populated with all of the messages that fall under the Presentation_Name. For Example, if I select Return Policy from the combo box, the combo box below it gets populated with only one message, "CC Regarding return policy"

    This is what I got so far:
    Thank You

    Code:
    Option Explicit
    Dim xmlNote As New DOMDocument
    Dim xmlNode As IXMLDOMNode
     
    Private Sub PopulateAddNotes()
        '// Load XML into DOM Object
        xmlNote.Load "C:\Notes.xml"
        
        '// Populate combo box with all presentation names
        For Each xmlNode In xmlNote.documentElement.selectNodes("//PRESENTATION_NAME")
            Combo1.AddItem xmlNode.Text
        Next
    End Sub
    
    Private Sub Combo1_Click()
        Dim strNoteType As String
        Dim xmlNodeList As IXMLDOMNodeList
            
        strNoteType = Combo1.Text
        Set xmlNodeList = xmlNote.documentElement.selectNodes("//PRESENTATION_NAME")
            
        For Each xmlNode In xmlNodeList
            If xmlNode.Text = strNoteType Then
                Combo2.AddItem xmlNode.parentNode.selectSingleNode("MESSAGES/MESSAGE/COMBO_NAME").Text
                Text1.Text = xmlNode.parentNode.selectSingleNode("MESSAGES/MESSAGE/TEXT_NAME").Text
            End If
        Next
    End Sub
    Code:
    <NOTES>
        <NOTE ID="104">		
            <PRESENTATION_NAME>Return Policy</PRESENTATION_NAME>
    	    <MESSAGES>
    	        <MESSAGE>
    		    <COMBO_NAME>CC Regarding return policy</COMBO_NAME>     		    
    		</MESSAGE>
    	    </MESSAGES>		
    	<PRESENTATION_NAME>Delivery Inquiry</PRESENTATION_NAME>				
    	    <MESSAGES>
    		<MESSAGE>
    		    <COMBO_NAME>CC Regarding delivery timing</COMBO_NAME>		    
    		</MESSAGE> 
    		<MESSAGE>
    		    <COMBO_NAME>CC Regarding delivery options</COMBO_NAME>		    
    		</MESSAGE>
    		<MESSAGE>
    		    <COMBO_NAME>CC Regarding delivery fees</COMBO_NAME>		    
    		</MESSAGE>
    	    </MESSAGES>	
        </NOTE>
    </NOTES>

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    In this code
    Code:
    For Each xmlNode In xmlNodeList
            If xmlNode.Text = strNoteType Then
                Combo2.AddItem xmlNode.parentNode.selectSingleNode("MESSAGES/MESSAGE/COMBO_NAME").Text
                Text1.Text = xmlNode.parentNode.selectSingleNode("MESSAGES/MESSAGE/TEXT_NAME").Text
            End If
        Next
    you are overwriting the text in Text1 each time you go through the loop. You need to do something like
    Code:
    For Each xmlNode In xmlNodeList
            If xmlNode.Text = strNoteType Then
                Combo2.AddItem xmlNode.parentNode.selectSingleNode("MESSAGES/MESSAGE/COMBO_NAME").Text
                Text1.Text = Text1.Text  & " " & xmlNode.parentNode.selectSingleNode("MESSAGES/MESSAGE/TEXT_NAME").Text
            End If
        Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width