XML總是一個挑戰....你的閱讀代碼高度依賴於編寫代碼,並希望它永遠不會改變。你的來源是陌生人之一。
我總是不得不去尋找網絡來尋找這些問題的解決方案,通常這些帖子與我手邊的XML工具版本不一致。通常,您可以使用IDE查看對象庫,並找到在帖子中找到的相應屬性和方法。在Excel中打開對象瀏覽器,您可以查看MSXML2庫。
Sub test()
' add reference to MSXML v6
'http://msdn.microsoft.com/en-us/library/aa468547.aspx
'http://msdn.microsoft.com/en-US/data/bb190600.aspx
Dim xdoc As New DOMDocument60
Dim s As String
s = s & "<Doc a=""1"" b=""2"">"
s = s & "<Doc1 aa=""1"" bb=""2"" cc=""3"" dd=""4""/>"
s = s & "<Doc1 aa=""1"" bb=""2"" cc=""3"" dd=""4"" ee=""5""/>"
s = s & "<Doc1 aa=""1"" bb=""2"" cc=""3"" dd=""4""/>"
s = s & "<Doc1 aa=""1"" bb=""2"" cc=""3"" dd=""4"" ff=""6""/>"
s = s & "<Doc1 aa=""1"" bb=""2"" cc=""3"" dd=""4"" gg=""7""/>"
s = s & "</Doc>"
xdoc.LoadXML (s)
DisplayNodes2 xdoc
End Sub
Sub DisplayNodes2(xmlDoc As DOMDocument60)
'http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/thread/454fbc72-ab87-4479-b0bf-b7925834ac4e/
Dim xelem As IXMLDOMElement
Dim xa As IXMLDOMAttribute
For Each xelem In xmlDoc.SelectNodes("//*")
Debug.Print xelem.nodeName
For Each xa In xelem.Attributes
Debug.Print xa.Name, xa.Value
Next xa
Next xelem
End Sub
你有沒有嘗試過任何解決這個問題的方法,如果可以的話,請你發貼嗎? – avalancha
或[搜索](http://stackoverflow.com/search?q) – 2013-06-18 13:48:12