Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse XML string

Status
Not open for further replies.

48Highlander

Technical User
Feb 8, 2004
119
CA
I have an XML string contained in a string variable. I am new to XML so would appreciate some guidance on getting started.
I am trying to extract the <Country> value from the string below:

<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<HostQueryRs statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<HostRet>
<ProductName>QuickBooks Pro</ProductName>
<MajorVersion>19</MajorVersion>
<MinorVersion>0</MinorVersion>
<Country>CA</Country>
<SupportedQBXMLVersion>1.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>1.1</SupportedQBXMLVersion>
<SupportedQBXMLVersion>2.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>2.1</SupportedQBXMLVersion>
<SupportedQBXMLVersion>3.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>4.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>4.1</SupportedQBXMLVersion>
<SupportedQBXMLVersion>5.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>6.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>7.0</SupportedQBXMLVersion>
<SupportedQBXMLVersion>8.0</SupportedQBXMLVersion>
<IsAutomaticLogin>false</IsAutomaticLogin>
<QBFileMode>SingleUser</QBFileMode>
</HostRet>
</HostQueryRs>
</QBXMLMsgsRs>
</QBXML>

I also need to cycle through the "SupportedQBXMLVersion" values to find the highest value.


Bill J
 
Something like:

Code:
[blue]    ' requires a reference to Microsoft XML library
    Dim XMLDoc As DOMDocument
    Dim myItem As IXMLDOMElement
    Dim MaxVal As String
    
    
    Set XMLDoc = New DOMDocument
    
    XMLDoc.loadXML Text1.Text
    For Each myItem In XMLDoc.getElementsByTagName("Country")
        MsgBox "Country: " & myItem.Text
    Next
    
    MaxVal = ""
    For Each myItem In XMLDoc.getElementsByTagName("SupportedQBXMLVersion")
        If myItem.Text > MaxVal Then MaxVal = myItem.Text
    Next
    MsgBox "Maximum Supported Version: " & MaxVal[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top