读取XML属性VBA

前端之家收集整理的这篇文章主要介绍了读取XML属性VBA前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在VBA中获取单个节点的属性,但无法使用DOM来管理它

XML如下所示:

<?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>

我基本上只是想获取ID属性的值.任何帮助,将不胜感激.

解决方法

尝试:

(包括对Microsoft XML v3的引用,我将xml保存到桌面上的文件中)

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

猜你在找的XML相关文章