On Error Resume Next Dim objDom As DOMDocument Dim objElement As IXMLDOMElement Dim objElement1 As IXMLDOMElement Dim objElement2 As IXMLDOMElement Dim pi As Integer Dim di As Integer Dim bi As Integer Set objDom = New DOMDocument objDom.Load g_path & "Response.xml" If objDom.documentElement Is Nothing Then MsgBox "xml文件不存在" Exit Sub End If Text1.Text = "" Set objElement = objDom.selectSingleNode(".//BODY")For bi = 0 To objElement.childNodes.length - 1 Set objElement1 = objElement.childNodes(bi) For di = 0 To objElement.childNodes(bi).childNodes.length - 1 If objElement.childNodes(bi).childNodes(di).baseName = "BEAN" Then Set objElement2 = objElement1.childNodes(di) Text1.Text = Text1.Text + objElement2.getAttribute("NAME") + " " + objElement2.getAttribute("HIGH") + " " + objElement2.getAttribute("USR_ID") + " " + objElement2.getAttribute("BIRTH") + vbCrLf End If Next di Next bi自己再改一改
Dim objDom As DOMDocument
Dim objNode As IXMLDOMElement
Set objDom = New DOMDocument
objDom.loadXML "<root><point name='tom' sex='male'>GGG</point></root>"
Set objNode = objDom.selectSingleNode("/root/point")
MsgBox objNode.getAttribute("name")
MsgBox objNode.getAttribute("sex")
End Sub
注意objNode为IXMLDOMElement类型。
请先引用MSXML,版本随意。
注意objNode为IXMLDOMElement类型。
换成vbs怎么就不可以了啊 ??
Dim objDom As DOMDocument
Dim objElement As IXMLDOMElement
Dim objElement1 As IXMLDOMElement
Dim objElement2 As IXMLDOMElement
Dim pi As Integer
Dim di As Integer
Dim bi As Integer
Set objDom = New DOMDocument
objDom.Load g_path & "Response.xml"
If objDom.documentElement Is Nothing Then
MsgBox "xml文件不存在"
Exit Sub
End If
Text1.Text = ""
Set objElement = objDom.selectSingleNode(".//BODY")For bi = 0 To objElement.childNodes.length - 1
Set objElement1 = objElement.childNodes(bi)
For di = 0 To objElement.childNodes(bi).childNodes.length - 1
If objElement.childNodes(bi).childNodes(di).baseName = "BEAN" Then
Set objElement2 = objElement1.childNodes(di)
Text1.Text = Text1.Text + objElement2.getAttribute("NAME") + " " + objElement2.getAttribute("HIGH") + " " + objElement2.getAttribute("USR_ID") + " " + objElement2.getAttribute("BIRTH") + vbCrLf
End If
Next di
Next bi自己再改一改