Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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
Old December 30th, 2004, 11:56 AM
Registered User
Join Date: Dec 2004
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. 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"

 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" />

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

 set domLine = xmlOrder.SelectSingleNode("//xml_orderline[@id='"& id &"' and @pid='"& pid &"']")

 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!

Old January 3rd, 2005, 12:37 PM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

It should work although there's a few un-needed steps. If you're not sure try viewing the dom after modifying it:
domLine.setAttribute CStr(param),CStr(val)
Response.contentType = "text/xml"
xmlOrder.save Response
I would also suggest you use a more modern class instead of "Microsoft.XMLDOM", see this post -


Joe (Microsoft MVP - XML)

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 Classic ASP XML 0 December 30th, 2004 11:59 AM
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.