读取XML属性VBA

我试图获取VBA中单个节点的属性,但无法使用DOM来pipe理它

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 

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