10

I am trying to get the attribute of a single node in VBA, but can't manage it using DOM

The XML looks like following:

<?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 am basically just trying to get the value of the ID attribute. Any help would be appreciated.

2 Answers 2

22

Try:

(Include a reference 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
Sign up to request clarification or add additional context in comments.

1 Comment

How would you check if the attribute exists first? edit: Attributes.getNamedItem("ID") Is Nothing
0

I tried using similar code to load and extract attributes from a web service provided XML file. It turns out that unless you set the xDoc.async property to false, xDoc.Load() returns immediately and then the rest of your code goes to waste.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.