Parsing XML in VBA (1 Viewer)

buratti

Registered User.
Local time
Today, 12:58
Joined
Jul 8, 2009
Messages
234
If anybody is keeping track, I did post a similar question a few months ago, but this is slightly different. I am receiving an XML document as a response from a server and I need to parse it and retrieve data from that document. There is sample code and documentation about how to do this provided from the SDK from the service I am receiving the response from, but their code is in vb.net and I can't seem to figure out exactly how/what the VBA equivalent would be for it. Here is a snippet of the code they provided (obviously VBA syntax is a little different but I changed it for my application:
Code:
'Parse the response XML string into an XmlDocument
Dim responseXmlDoc as [COLOR=red]XmlDocument[/COLOR]
responseXmlDoc = new [COLOR=red]XmlDocument[/COLOR]();
responseXmlDoc.LoadXml(response)
 
'Get the response for our request
Dim CustomerCreditCardWalletAddRsList As [COLOR=red]XmlNodeList[/COLOR]
CustomerCreditCardWalletAddRsList = responseXmlDoc.GetElementsByTagName("CustomerCreditCardWalletAddRs")
if (CustomerCreditCardWalletAddRsList[COLOR=black].Count[/COLOR] = 1) 
Dim responseNode As XmlNode
responseNode = CustomerCreditCardWalletAddRsList.Item(0);
'Check the status code, info, and severity
Dim rsAttributes as [COLOR=darkred][COLOR=red]XmlAttributeCollection[/COLOR]
[/COLOR]rsAttributes = responseNode.Attributes;
Dim statusCode As String
Dim statusSeverity As String
Dim statusMessage As String
statusCode = rsAttributes[COLOR=black].GetNamedItem[/COLOR]("statusCode").Value
statusSeverity = rsAttributes.[COLOR=black]GetNamedItem[/COLOR]("statusSeverity").Value
statusMessage = rsAttributes[COLOR=black].GetNamedItem[/COLOR]("statusMessage").Value

The problem I am having with this is declaring the objects. I have a reference to Microsoft XML, v6.0 in my project. All of the items in red are my particular problems. It seems that "XMLDocument", "XMLNode", "XMLNodeList", and "XMLAttributCollection" is not part of the Microsoft XML, v6.0 collection. I did find, at least I think, equevalents of the above types, but still having a problem with one in particular... the "XMLAttributeCollection".

Here is my modified code with the changes in green:

Code:
 ...
'Parse the response XML string into an XmlDocument
Dim responseXmlDoc As [COLOR=seagreen]MSXML2.DOMDocument[/COLOR] 'as opposed to XMLDocument
Set responseXmlDoc = [COLOR=seagreen]New MSXML2.DOMDocument[/COLOR] 'as opposed to XMLDocument
responseXmlDoc.LoadXML (response)
'Get the response for our request
Dim CustomerCreditCardWalletAddRsList As [COLOR=seagreen]MSXML2.IXMLDOMNodeList[/COLOR]  'as opposed to XmlNodeList
CustomerCreditCardWalletAddRsList = responseXmlDoc.getElementsByTagName("CustomerCreditCardWalletAddRs")
Dim responseNode As [COLOR=seagreen]MSXML2.IXMLDOMNode[/COLOR] 'as opposed to XmlNode
responseNode = CustomerCreditCardWalletAddRsList.Item(0)
'Check the status code, info, and severity
Dim rsAttributes As [COLOR=red]???[/COLOR] [COLOR=red]'Could not fine the equivalent to XmlAttributeCollection[/COLOR]
rsAttributes = responseNode.Attributes
Dim statusCode As String
Dim statusSeverity As String
Dim statusMessage As String
statusCode = rsAttributes.getNamedItem("statusCode").Value
statusSeverity = rsAttributes.getNamedItem("statusSeverity").Value
statusMessage = rsAttributes.getNamedItem("statusMessage").Value
...

So how should I go about setting this type, or am I just using the wrong reference all together?
 
Last edited:

GanzPopp

Registered User.
Local time
Today, 18:58
Joined
Jan 14, 2013
Messages
37
It should be:
Code:
Dim rsAttributes As MSXML2.IXMLDOMNamedNodeMap
 

Users who are viewing this thread

Top Bottom