作者:baiwei001 | 来源:互联网 | 2023-05-18 16:55
Goodday,Environment:Excel2007,MSXML6.0,Sharepoint3环境:Excel2007,MSXML6.0,Sharepoint3I
Good day,
Environment: Excel 2007, MSXML 6.0, Sharepoint 3
环境:Excel 2007,MSXML 6.0,Sharepoint 3
I would like to parse a Sharepoint SOAP response which is returned after creating new rows in a Sharepoint list. I do however not get to the elements I wish to. I am sure I do overlook something obvious.
我想解析在Sharepoint列表中创建新行后返回的Sharepoint SOAP响应。但是,我没有达到我想要的元素。我相信我确实忽略了一些明显的东西。
I would like to return:
我想回复:
1) The ID of the result - this is causing issues 2) Result Error Number - works accessing the node 3) Result Error Text (if existing) - works accessing the node
1)结果的ID - 这导致问题2)结果错误号 - 访问节点的工作3)结果错误文本(如果存在) - 工作访问节点
ID 1 is a success response, ID 2 is a failure response. I am also wondering why ID 1 has a closing ID tag which ID 2 has not and if this may causes problems.
ID 1是成功响应,ID 2是失败响应。我也想知道为什么ID 1有一个ID ID没有的结束ID标签,如果这可能导致问题。
This is what I have so far:
这是我到目前为止:
Sub Parse_Soap_Response()
Dim xml_soap_response As String
Dim xml_document As Object 'New MSXML2.DOMDocument60
Dim xml_nodes_collection As Variant 'IXMLDOMSelection
Dim xml_node_element As Variant 'IXMLDOMElement
Dim xml_node_attributes As Variant 'IXMLDOMNamedNodeMap
Dim xml_node_attribute As Variant 'IXMLDOMAttribute
Set xml_document = CreateObject("MSXML2.DOMDocument.6.0")
'Set XML opening options
With xml_document
.Async = False
.PreserveWhiteSpace = False
.ValidateOnParse= False
.ResolveExternals = False
'Use full XPath functionality
.SetProperty "SelectionLanguage", "XPath"
'Add specific Namespaces to work with Paths
.SetProperty "SelectionNamespaces", "xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" " & _
"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " & _
"xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" " & _
"xmlns=""http://schemas.microsoft.com/sharepoint/soap/"" " & _
"xmlns:rs=""urn:schemas-microsoft-com:rowset"" " & _
"xmlns:z=""#RowsetSchema"""
End With
xml_soap_respOnse= _
" " & _
" " & _
" " & _
" " & _
" " & _
" " & _
" " & _
" 0x00000000 " & _
" " & _
" " & _
" " & _
" 0x81020014 " & _
" One or more field types are not installed properly. Go to the list settings page to delete these fields. " & _
" " & _
" " & _
" " & _
" " & _
" " & _
""
'Load XML File and report Error if any
If Not xml_document.LoadXML(xml_soap_response) Then
MsgBox "Error while loading XML File:" & vbCrLf & vbCrLf & _
"Line Number " & xml_document.parseError.Line & vbCrLf & _
xml_document.parseError.reason & " (" & xml_document.parseError.ErrorCode & ")", vbCritical, "Error"
Exit Sub
End If
Set xml_nodes_collection = xml_document.SelectNodes("//soap:Envelope/soap:Body/UpdateListItemsResponse/UpdateListItemsResult/Results")
'Go through all nodes
For Each xml_node_element In xml_nodes_collection
'Go through all attributes
For Each xml_node_attribute In xml_node_element.attributes
'Should return
'1) The ID of the result
'2) Result Error Number
'3) Result Error Text
Debug.Print xml_node_attribute.nodename & "=" & xml_node_attribute.NodeValue
Next
Next
'Close the xml document
Set xml_document = Nothing
End Sub
Thanks in advance for any help.
在此先感谢您的帮助。
1 个解决方案