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>
Govinda2020Asked:
Who is Participating?
 
zc2Connect With a Mentor Commented:
If you need to delete only one of them, then you have to correct the XPath expression (the string argument which is passed to the selectSingleNode() call) that way so the correct node will be found.
If you need to delete both of them (or more), instead of the selectSingleNode() call use selectNodes() and then process each of the list of found nodes the same way as single node.
0
 
käµfm³d 👽Commented:
What language are you using?
0
 
zc2Commented:
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

0
 
Govinda2020Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.