Govinda2020
asked on
Delete a node in XML
I have a situation where a node has to be deleted from XML file.I am trying to delete the below node from the attached.Any suggestions.
<ac:time status="63">
<ac:integer>235959</ac:int eger>
</ac:time>
<ac:time status="63">
<ac:integer>235959</ac:int
</ac:time>
What language are you using?
Here's a sample, how to select and delete a node using VBScript
You need to correct it, placing the right "ac" namespace definition in the line 15
I reads the source from a file named ac.xml
You need to correct it, placing the right "ac" namespace definition in the line 15
I reads the source from a file named ac.xml
Option Explicit
Dim xml
set xml = CreateObject("Msxml2.DOMDocument.6.0")
xml.async = False
xml.validateonparse=false
xml.setProperty "ProhibitDTD", false
' 1. read the XML
xml.load("ac.xml")
if xml.parseError.errorCode <> 0 then
WScript.Echo "Error: " & xml.parseError.errorCode & " Reason: " & xml.parseError.reason
end if
call xml.setProperty("SelectionLanguage", "XPath")
call xml.setProperty("SelectionNamespaces", "xmlns:ac='ac'")
' 2. Delete node
dim e, nm
set e = xml.documentElement.selectSingleNode("//ac:time[@status='63']")
if not e is Nothing then e.parentNode.removeChild( e )
WScript.Echo xml.xml
ASKER
Thanks ZC2 , I will try this and let you know. But the issue I have there are two nodes with the same name i.e ac:integer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.