I need to delete an node in an XML, my XML looks as below
<message_version>Test</message_version>
<responder_id>My test XML file</responder_id>
</m_control>
<m_content>
<b_control>
<quote_response_status>error</quote_response_status>
<quote_error_note>
<reason>
<note>
<text>An error occurred.
</text>
</note>
</reason>
</quote_error_note>
</b_control>
In the above xml i need to remove the node “text” and “note”, keepimg the text “An error occurred.” untouched. How can i achieve that.
basically i need an XML as below after removing the node ‘text’ and ‘note’
<message_version>Test</message_version>
<responder_id>My test XML file</responder_id>
</m_control>
<m_content>
<b_control>
<quote_response_status>error</quote_response_status>
<quote_error_note>
<reason>
An error occurred.
</reason>
</quote_error_note>
</b_control>
I have tried the following with no sucess:
sXMLPath = "//message/m_content/b_control/quote_error_note/reason"
Set sRemoveText = m_objResponseXML.selectSingleNode(sXMLPath & "/note/text")
Set sRemoveNote = m_objResponseXML.selectSingleNode(sXMLPath & "/note")
If Not sRemoveText is Nothing Then
m_objResponseXML.selectSingleNode(sXMLPath & "/note").removeChild(sRemoveText)
sErrorMsg = GetNodeText(sXMLPath & "/note/text", m_objResponseXML)
End if
If Not sRemoveText is Nothing Then
m_objResponseXML.selectSingleNode(sXMLPath).removeChild(sRemoveNote)
End If
If sErrorMsg <> "" Then
m_objResponseXML.selectSingleNode(sXMLPath).text = sErrorMsg
End If
Any kind of help is deeply appreciated.
To examplify Rafael’s advice with code and to give you some search/keywords to look for when reading the Docs:
output: