Reading VBA XML Attribute

I am trying to get the attribute of a single node in VBA, but I cannot control it using the DOM

XML is as follows:

<?xml version="1.0" encoding="utf-8"?>
   <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Body>
         <GetUserInfoResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">
            <GetUserInfoResult>
               <GetUserInfo>
                  <User ID="16" Name="" LoginName="login" Email="" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
            </GetUserInfo>
         </GetUserInfoResult>
      </GetUserInfoResponse>
   </soap:Body>
</soap:Envelope>

I'm just trying to get the ID attribute value. Any help would be appreciated.

+3
source share
2 answers

Try:

(Include the link to Microsoft XML v3, I saved your xml to a file on my desktop)

Dim xmlDoc As DOMDocument30
Set xmlDoc = New DOMDocument30
xmlDoc.Load ("C:\users\jon\desktop\test.xml")

Dim id As String
id = xmlDoc.SelectSingleNode("//GetUserInfo/User").Attributes.getNamedItem("ID").Text
+13
source

I tried using similar code to load and retrieve attributes from the provided XML web service file. It turns out that if you do not set the xDoc.async property to false, xDoc.Load () returns immediately, and the rest of your code will be dragged away.

0
source

All Articles