如何在 vbscript 中到达元素 XML 的第二个 child 节点?

How do I reach the second child node of an element XML in vbscript?

在互联网上花了很多时间后,我无法让它工作,需要一些帮助。

XML:

xml snippet highlighting NoteSynopsis

代码:

set xmlDoc  = SERVER.CREATEOBJECT("MSXML2.DomDocument.6.0")
xmlDoc.async = False              xmlDoc.Load("D:\GVPApplications\TechSupportCreateIncident\CreateIncidentRequest.xml")    
xmlDoc.setProperty "NewParser","true"               

set Root = xmlDoc.documentElement

set NodeList1 = Root.getElementsByTagName("IncidentNote")

                 For Each Elem in NodeList1
                     if Elem.firstChild.nodename = "Note" then
                          Elem.firstChild.text = Notes
                     end if

                 Next

问题: 如图 XML 中突出显示的那样,我需要能够读取 "NoteSynopsis" 元素及其值。看起来很简单,但我一直无法找到解决方案。如果这是最后一个 child 没问题,我会做一个 Elem.LastChild.nodename,但这不是!

您可以使用 selectSingleNode(...) 方法并使用 XPath

set xmlDoc  = SERVER.CREATEOBJECT("MSXML2.DomDocument.6.0")
xmlDoc.async = False              xmlDoc.Load("D:\GVPApplications\TechSupportCreateIncident\CreateIncidentRequest.xml")    
xmlDoc.setProperty "NewParser","true"
xmlDocument.setProperty "SelectionLanguage", "XPath"               

Dim firstIncidentNote
set firstIncidentNote = xmlDoc.SelectSingleNode("//IncidentNote")
Dim note
Dim noteSynopsis
set note = firstIncidentNote.GetAttribute("Note")
set note = firstIncidentNote.GetAttribute("NoteSynopsis")

https://msdn.microsoft.com/en-us/library/ms757846(v=vs.85).aspx