在VBScript中解析XML时访问一条信息时出现问题

时间:2018-09-11 17:13:40

标签: xml vbscript

我的代码将遍历我的XML文件,并拔出TO,FROM和SUBJECT,效果很好。我遇到的问题是我不知道如何从ELEMENT节点提取ID属性。我需要用它来标识保存电子邮件内容的文件名。我尝试过的一切似乎都没有效果。理想情况下,将ID添加到Sub Invite_Merge(meeting_date As Date, meeting_time As Double, meeting_duration As Integer, client_email As String, meeting_subject As String, meeting_location As String, client_name As String, meeting_body As String, meeting_sender As String) Dim O As Outlook.Application Set O = New Outlook.Application Dim OAPT As Outlook.AppointmentItem Set OAPT = O.CreateItem(olAppointmentItem) OAPT.MeetingStatus = olMeeting Dim meeting_start meeting_start = DateValue(meeting_date) + meeting_time With OAPT .Recipients.Add (client_email) .Subject = meeting_subject .Start = meeting_start .Duration = meeting_duration .Location = meeting_location .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>" .Display '.Send End With End Sub Sub Send_Invites() row_number = 2 Do DoEvents row_number = row_number + 1 If IsEmpty(Sheet1.Range("D" & row_number)) = False Then Call Invite_Merge(Sheet1.Range("A" & row_number), Sheet1.Range("B" & row_number), Sheet1.Range("C" & row_number), Sheet1.Range("D" & row_number), Sheet1.Range("E" & row_number), Sheet1.Range("F" & row_number), Sheet1.Range("G" & row_number), Sheet1.Range("H" & row_number), Sheet1.Range("A" & "1")) End If Loop Until row_number = 100 End Sub

以下是我正在使用的XML的示例:

Screenshot of XML data.

这是我的代码:

strQuery

1 个答案:

答案 0 :(得分:1)

获取父节点的ID属性:

WScript.Echo objNode.ParentNode.GetAttribute("ID")

或者,选择<ELEMENT>节点,获取其ID属性,然后选择所需的子节点:

For Each objNode In xmlDoc.SelectNodes("//ELEMENT")
    WScript.Echo objNode.GetAttribute("ID")
    WScript.Echo objNode.SelectSingleNode("./FROM").Text
    WScript.Echo objNode.SelectSingleNode("./TO").Text
    ...
Next

不建议使用Microsoft.XMLDOM。请改用Msxml2.DOMDocument.6.0