我需要删除 XML 中的一个节点,我的 XML 如下所示
<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>
在上面的 xml 中,我需要删除节点“文本”和“注释”,并保留文本“发生错误”。原封不动。我怎样才能做到这一点。
基本上,在删除节点“文本”和“注释”后,我需要如下 XML
<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>
我尝试了以下但没有成功:
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
任何形式的帮助都深表感谢。