Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 30th, 2004, 11:59 AM
Registered User
 
Join Date: Dec 2004
Location: The Hague, , Netherlands.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP3 / XMLDOM / updating nodes -- HELP PLEASE

Hello everyone!

I got a problem here (I use ASP (3.0) with Microsoft.XMLDOM). The thing is I have an XML tree with some information. And I need to modify data stored in it. It's a simple 2-level structure. Please just provide me a working example of how to modify the data in some node/attribute of this node and then to save the complete modified XML structure back to the Session variable.

I tried to do it the following way but it seems it's not working..

sub init()
 set xmlOrder = Server.CreateObject("Microsoft.XMLDOM")
 set xmlOrderItem = xmlOrder.createElement("xml_order")
 xmlOrderItem.setAttribute "id","1"
 xmlOrderItem.setAttribute "name","my order"

 xmlOrder.appendChild(xmlOrderItem)
 set Session("XML_ORDER") = xmlOrder
 set xmlOrderItem = nothing
 set xmlOrder = nothing
end sub

... i also have the procedure which adds the second level (xml_orderline) to the initialized tree:
 <xml_order id="1" name="my order">
   <xml_orderline id="11" pid="11" name="bmw" />
   <xml_orderline id="12" pid="11" name="mercedes" />
   <xml_orderline id="13" pid="11" name="lada" />
 </xml_order>

So, this part (creation) is working fine. But when it comes to editing the data within the attribute, it seems just doesn't change them.

sub change_data(id,pid,param,val)
 dim domLine, domLines, xmlOrderItem, xmlOrder
 set xmlOrder = Session("XML_ORDER")
 On Error Resume Next
 dim tmp : tmp = xmlOrder.getAttribute("id")
 If Err <> 0 Then ' error occurred
    set xmlOrder = xmlOrder.documentElement
 End If

 'RETRIEVE THE ORDERLINE BY collectionId
 set domLine = xmlOrder.SelectSingleNode("//xml_orderline[@id='"& id &"' and @pid='"& pid &"']")

 'UPDATE THE FIELD WITH THE NEW VALUE
 domLine.setAttribute CStr(param),CStr(val)


 ' i am not sure whether the data is been modified by XMLDOM
 ' object automatically after I run setAttribute() method
 ' or is this all i have done here correct?


 set Session("XML_ORDER") = xmlOrder
 set domLine = nothing
 set xmlOrder = nothing
end sub



Thank you very much in advance!




Similar Threads
Thread Thread Starter Forum Replies Last Post
access sub nodes using XMLDOM lian_a Classic ASP XML 2 January 19th, 2005 09:43 PM
ASP3 / XMLDOM / updating nodes -- HELP PLEASE Michael Yevdokimov XML 1 January 3rd, 2005 12:37 PM
updating nodes? pafo C# 0 November 11th, 2004 08:22 PM
ASP3.0 with XP version shezawi ASP.NET 1.0 and 1.1 Basics 5 October 30th, 2003 12:01 AM
Dfference between ASP2.0 and ASP3.0 hrishimusale ASP.NET 1.0 and 1.1 Basics 1 August 27th, 2003 08:18 AM





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