Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 29th, 2006, 06:51 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
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.

Reply With Quote
  #2 (permalink)  
Old March 20th, 2006, 02:25 PM
Authorized User
 
Join Date: Mar 2006
Location: Chennai, Tamil Nadu, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:06 AM.


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