|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#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:22 PM. |
|
#2
|
|||
|
|||
|
woah, what neck of the woods are we in here?
To begin with, if you're going to be using XML as a database structure you should use EMPTY elements rather than plain element declaration. Speaking of which, where the hell is your DTD? well, in anycase i guess you don't really need it but it's good programming practice. well, how about we start out with setting it to the document root? then how about we get by .getElementsByTagName("blah"). when you get that. ObjOldChild = objParent.removeChild(objParent.lastChild); Secondly, you don't have a unique identifier for article. I think that's your problem but i don't work with this form of xml, it's kinda not good and it's generally stressed to use attribute EMPTY elements instead. This is generally how W3C is aiming Code:
<NEWS>
<ARTICLE
articleID="art01"
Des="Testing 123"
Date="1/9/2003"
/>
<ARTICLE
articleID="art02"
Des="Testing 321"
etc....
</NEWS>
this will dramatically reduce your document size which will be a big issue since the purpose of XML is marshalling data. You won't see a dramatic speed increase with this since DOM loads everything into memory first, but when you get into SAX and more advacned XML handling methods you'll begin to see a performance increase with attribute usage and 'containment'. But of course performance is a big thing with XML since it's already slow enough, but if i remember correctly you were knew, or maybe it was just new to asp, but in anycase, let me know if you still need help. Hope this helps, but i'm not a master of doing it the way you're currently handling this.... if you want to switch to my way we can talk =P |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Delete item from xml??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|