如果通过添加文档元素将其更正为有效 XML:
<doc>
<abc>
<ab>value</ab>
<aa>time</aa>
<ac>money</ac>
</abc>
<abc>
<ab>right</ab>
<aa>left</aa>
<ac>straight</ac>
</abc>
</doc>
您可以执行以下操作:
Dim DOM As MSXML2.DOMDocument
Dim Node As MSXML2.IXMLDOMNode
Set DOM = New MSXML2.DOMDocument
With DOM
.async = False
.preserveWhiteSpace = True
If .Load("sample.xml") Then
.setProperty "SelectionLanguage", "XPath"
Set Node = .selectSingleNode("//*[.='left']")
If Not Node Is Nothing Then
.documentElement.removeChild Node.parentNode
On Error Resume Next
Kill "sample.xml"
On Error GoTo 0
.save "sample.xml"
MsgBox "Done, saved as sample.xml"
Else
MsgBox "No ""left"" found"
End If
Else
MsgBox "Load failed!" & vbNewLine & vbNewLine _
& CStr(.parseError.errorCode) & " " _
& .parseError.reason
End If
End With