Wrox Programmer Forums
|
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2006, 06:51 PM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP/XML Trying to delete a xmlnode

I posted this in an earlier topic, but it was in the wrong forumsection.


I am facing a similar problem, where I am **trying** to delete a node in the middle of similar nodes, eg trying to delete b(1) (with c2 value "Hello!"):


<?xml version="1.0"?>
<a>
 <b>
  <c1></c1>
  <c2></c2>
 </b>
 <b>
  <c1></c1>
  <c2>Hello!</c2>
 </b>
 <b>
  <c1></c1>
  <c2></c2>
 </b>
</a>



The code I have so far is:

Set o_xmlSettingsDocument=Server.CreateObject("Microso ft.XMLDOM")
o_xmlSettingsDocument.async=false
o_xmlSettingsDocument.load(Server.MapPath("system\ settings.xml"))

function f_DeleteXMLLink(v_intLink)
    dim v_strReturn
    dim o_xmlNode

    set o_xmlNode=Server.CreateObject("Microsoft.XMLDOM")

    set o_xmlNode=o_xmlSettingsDocument.getElementsByTagNa me("a/b[" & v_intLink & "]")

    Set o_xmlSettingsDocument = o_xmlNode.removechild(o_xmlSettingsNode.item(v_int Link))

    set o_xmlNode=nothing

    f_DeleteXMLLink=v_strReturn
end function



Like I said before, I _bet_ you don't know the answer.

 
Old March 20th, 2006, 02:25 PM
Authorized User
 
Join Date: Mar 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Raghunathan
Default

Hi,

Here i've written a function for deleting a specific node from the xml file.
As you've asked, this function accepts a string as arguments (in your case it is the string "Hello"), the function searches
for the given string in a particular node (here it is node "c2"). if a matching node is found, it will be deleted from the
xml document and document gets saved.

the function will return true or false based on the operation done
here i've used XPATH queries to search the nodes in the xml document (one of the fastest way)
hope this function would help solve your problem


function deleteXMLNode(strText)
    Dim xmlDoc, xmlNode
    Dim bDeleted

    Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

    xmlDoc.Load Server.MapPath("system\settings.xml")

    Set xmlNode = xmlDoc.selectSingleNode("a/b[c2='" & Trim(strText) & "']")

    If Not xmlNode Is Nothing Then
        xmlDoc.documentElement.removeChild xmlNode
        bDeleted = True
    Else
        bDeleted = False
    End If

    xmlDoc.Save Server.MapPath("system\settings.xml")

    deleteXMLNode = bDeleted
end function



Regards,
Raghu





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete a xml node with all attributes and s vishnu108mishra XML 2 November 14th, 2007 04:19 AM
delete XML node in Perl crmpicco Perl 4 November 28th, 2006 12:12 PM
delete XML node with javascript crmpicco Javascript How-To 5 April 6th, 2006 03:35 AM
xmldocument & xmlnode albusr .NET Web Services 2 December 20th, 2005 01:46 PM
Service returns xmlNode instead of xmlDocument! KC7ZDM .NET Web Services 0 February 18th, 2005 08:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.