개발2013. 8. 13. 11:33
300x250

** 출처 : http://www.vbforums.com/showthread.php?642389-Resolved-VB6-read-XML


<?xml version="1.0"?>
<wclass>
	<item id="69">
	<productid>VB6</productid>
	<quantity>2</quantity>
	</item>

	<item id="70">
	<productid>C++</productid>
	<quantity>3</quantity>
	</item>
</wclass>


Dim xmlDoc As DOMDocument
Dim objNodeList As IXMLDOMNodeList
Dim objProductNode As IXMLDOMNode
Dim objQuantityNode As IXMLDOMNode
Dim objNode As IXMLDOMNode
Dim XMLurl As String
Dim strRet As String

    Set xmlDoc = New DOMDocument
    XMLurl = "http://www.xxx.com/orderxml.xml"
    
    xmlDoc.async = False
    
    If xmlDoc.Load(XMLurl) = False Then
        MsgBox ("XML LOAD ERROR")
    Else
        Set objNodeList = xmlDoc.selectNodes("//item")
        For Each objNode In objNodeList
            Set objProductNode = objNode.selectSingleNode("productid")
            Set objQuantityNode = objNode.selectSingleNode("quantity")
            
            strRet = "ProductID = " & objProductNode.Text & vbCrLf & _
                "Quantity = " & objQuantityNode.Text
            MsgBox strRet
        Next objNode
    End If


MSXML 을 참조해 놓아야 한다.


300x250
Posted by 마스타