Xml SOAP中带xpath的VBA DOM SelectSingleNode
这是我的XML文件:Xml SOAP中带xpath的VBA DOM SelectSingleNode,xml,vba,dom,xpath,Xml,Vba,Dom,Xpath,这是我的XML文件: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.5"> <soapenv:Header/> <soapenv:Body> <ns:listTransPattern> <searchCriteri
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.5">
<soapenv:Header/>
<soapenv:Body>
<ns:listTransPattern>
<searchCriteria>
<pattern>%</pattern>
<routePartitionName>%</routePartitionName>
<description>%</description>
</searchCriteria>
<returnedTags>
<pattern>?</pattern>
<routePartitionName>?</routePartitionName>
<description>?</description>
</returnedTags>
</ns:listTransPattern>
</soapenv:Body>
</soapenv:Envelope>
%
%
%
?
?
?
我试图添加一个与
并行的元素。如何在VBA中实现它?多谢各位 如下所示
如果要使用XPath表达式选择该元素,必须首先使用.setProperty“SelectionLanguage”
设置适当的选择命名空间
我知道XML文件只能有一个根。但是,如果您查看我的原始帖子中的XML文件,我试图添加的节点实际上并不在根节点。只是VBA认为它是“ns”命名空间中的根。所以我的问题是-如何更改名称空间来解决它?出于我的教育目的,在SelectSingleNode(XPath)中引用名称空间而不首先定义名称空间的语法是什么?非常感谢。要对该元素使用xpath,必须指定名称空间。替代方法可能包括从文档中删除名称空间,并在不使用xpath的情况下遍历结构。我修好了。仍然需要有关如何与并行添加元素的帮助。非常感谢你!我贴出了答案。让我知道。非常感谢!这就是我想要的——XPath中的引用命名空间。
Option Explicit
Sub test()
Dim xTEST As New MSXML2.DOMDocument60
With xTEST
.validateOnParse = True
.setProperty "SelectionLanguage", "XPath"
.async = False
.setProperty "SelectionNamespaces", "xmlns:ns=""http://www.cisco.com/AXL/API/10.5"""
If Not .Load("C:\Test.xml") Then
Err.Raise .parseError.ErrorCode, , .parseError.reason
End If
Dim a As IXMLDOMElement
Set a = .SelectSingleNode("//ns:listTransPattern").appendChild(.createElement("Status"))
End With
End Sub