读取XML属性VBA

读取XML属性VBA,xml,excel,dom,vba,soap,Xml,Excel,Dom,Vba,Soap,我试图在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/XM

我试图在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保存到桌面上的文件中)


我尝试使用类似的代码从web服务提供的XML文件中加载和提取属性。事实证明,除非将xDoc.async属性设置为false,否则xDoc.Load()会立即返回,然后代码的其余部分将被浪费。

如何首先检查该属性是否存在?编辑:Attributes.getNamedItem(“ID”)什么都不是
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