|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Delete item from xml??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|