XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 31st, 2003, 12:25 PM
DaronTan DaronTan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Malaysia
Posts: 49 DaronTan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 23 sec
Reputation Power: 5
Send a message via AIM to DaronTan Send a message via MSN to DaronTan Send a message via Yahoo to DaronTan
Question Delete item from xml???

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"?>
<!-- Edited with XML Spy v4.2 -->
<News>
<Article>
<Head>Test 1</Head>
<Des>Testing 123</Des>
<Date>1/9/2003</Date>
</Article>

<Article>
<Head>Test 2</Head>
<Des>Testing 321</Des>
<Date>1/9/2003</Date>
</Article>
</News>
-------------------------------------------------


*** 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
%>
-------------------------------------------------
--------------------------------

Last edited by DaronTan : August 31st, 2003 at 02:26 PM.

Reply With Quote
  #2  
Old September 2nd, 2003, 01:06 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
Of course not, getElementsByTagName returns a NodeList, here's a snipit showing you all the element names from your example. Since nodelist is not a child of the document it cannot possibly remove that item. Excuse the Javascript, it's what i'm used too and gives better error messages with XML =P


<html>
<head><title>Dom</title>
<script language="Javascript">

var objDOM;
objDOM = new ActiveXObject("MSXML.DOMDocument");
objDOM.async=false;
objDOM.load("News.xml");

var objMainNode;
objMainNode = objDOM.documentElement.firstChild;

var objNewNode;
objNewNode = objDOM.getElementsByTagName("Article")

for(i=0;i<objNewNode.length;i++){
alert(objNewNode.item(i).nodeName);
}


objDOM.removeChild(objNewNode.item(0));
alert(objDOM.xml);
</script>

You'll need to lookinto this

function deleteNode(sKey)
* Remove a "node" element matching a filtered "key" value

Reply With Quote
  #3  
Old September 2nd, 2003, 01:19 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
Here's a quick little tutorial to help you understand a little better i hope....

<html>
<head><title>Dom</title>
<script language="Javascript">

var objDOM;
objDOM = new ActiveXObject("MSXML.DOMDocument");
objDOM.async=false;
objDOM.load("News.xml");

var objMainNode;
objMainNode = objDOM.documentElement;

alert(objMainNode.xml);

var objNewNode;
objNewNode = objDOM.getElementsByTagName("Article")

for(i=0;i<objNewNode.length;i++){
alert(objNewNode.item(i).nodeName);
}
var newNodeitem, objNode, objText;
objNodeitem = objMainNode.firstChild.cloneNode(true);
objMainNode.appendChild(objNodeitem);
alert(objDOM.xml);

objMainNode.removeChild(objNodeitem);
alert(objDOM.xml);
</script>
</head>
<body>
<p>Stuff</p>
</body>
</html>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Delete item from xml???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway