xml="<note><to>George</to><from>John</from><heading>Reminder</heading ><body remark=""szqlay"">Don't forget the meeting!</body></note>"
Dim xmldocSet xmldoc = WScript.CreateObject("msxml2.domdocument")
xmldoc.async=false
xmldoc.loadxml(xml)
dim cnode
Set cnode=xmldoc.getElementsByTagName("body").item(0)
MsgBox cnode.text
MsgBox cnode.attributes.item(0).text
说实在,用数字作标签估计行不通,我试了下不能。这是用vbs脚本,或许放到vb中也行。你可自己把body改成数字试一下。
追答Private Sub Command1_Click()
Dim xml
xml = "<note><to>George</to><from>John</from><heading>Reminder</heading ><body remark=""szqlay"">Don't forget the meeting!</body></note>"
Dim xmldoc
Set xmldoc = CreateObject("msxml2.domdocument")
xmldoc.async = False
xmldoc.loadxml (xml)
Dim cnode
Set cnode = xmldoc.getElementsByTagName("body").Item(0)
MsgBox cnode.Text
MsgBox cnode.Attributes.Item(0).Text
End Sub
‘你复制到vb中,能运行了,这个CreateObject("msxml2.domdocument") 建立xmlDocument对象,是转门解析xml文本的。