Delete item from xml???

[b][red]This message was edited by DaronTan at 2003-8-31 12:9:27[/red][/b][hr]
Please tell me wat's wrong with the code below
I'd try both way in the asp file to delete the childnode in xml but it couldn't work

*** News.xml ***
-------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>



Test 1
Testing 123
1/9/2003



Test 2
Testing 321
1/9/2003


-------------------------------------------------


*** file.asp ***
-------------------------------------------------
<%
If Request.QueryString("Action")="Delete" Then
Dim strID
Dim objXML
Dim subArticle
Dim objLst
Dim subLst

strID = CInt(Request.Form("selectAnnouncement"))

Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.Load(Server.MapPath("News.xml"))

**** 01 ****
Set objLst = objXML.getElementsByTagName("Article")
Set subLst = objLst.item(strID)
objXML.documentElement.removeChild subLst

**** 02 ****
'Set subArticle = objXML.documentElement.childNodes(strID)
'objXML.documentElement.removeChild (subArticle)

Set childNode = Nothing
End If
%>
-------------------------------------------------

Comments

  • : [b][red]This message was edited by DaronTan at 2003-8-31 12:9:27[/red][/b][hr]
    : Please tell me wat's wrong with the code below
    : I'd try both way in the asp file to delete the childnode in xml but it couldn't work
    :
    : *** News.xml ***
    : -------------------------------------------------
    : <?xml version="1.0" encoding="ISO-8859-1"?>
    :
    :
    :
    : Test 1
    : Testing 123
    : 1/9/2003
    :
    :
    :
    : Test 2
    : Testing 321
    : 1/9/2003
    :
    :
    : -------------------------------------------------
    :
    :
    : *** file.asp ***
    : -------------------------------------------------
    : <%
    : If Request.QueryString("Action")="Delete" Then
    : Dim strID
    : Dim objXML
    : Dim subArticle
    : Dim objLst
    : Dim subLst
    :
    : strID = CInt(Request.Form("selectAnnouncement"))
    :
    : Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    : objXML.Load(Server.MapPath("News.xml"))
    :
    : **** 01 ****
    : Set objLst = objXML.getElementsByTagName("Article")
    : Set subLst = objLst.item(strID)
    : objXML.documentElement.removeChild subLst
    :
    : **** 02 ****
    : 'Set subArticle = objXML.documentElement.childNodes(strID)
    : 'objXML.documentElement.removeChild (subArticle)
    :
    : Set childNode = Nothing
    : End If
    : %>
    : -------------------------------------------------
    :

    Hi,

    Both methods shud be working. Try printing out the XML source [ Response.write (objXML.xml) ] after deleting. It should have been deleted. If you wanted to save the new XML, you have to call objXML.save(Server.MapPath("News.xml")).

    :)heers,
    Vanith

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion