Link to home
Start Free TrialLog in
Avatar of Govinda2020
Govinda2020Flag for Ireland

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:integer>
        </ac:time>
Avatar of kaufmed
kaufmed
Flag of United States of America image

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

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

Open in new window

Avatar of Govinda2020

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
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial