Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Updating XML Child nodes using Classic ASP Problems
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
abruton  
View profile  
 More options Oct 30, 10:50 am
Newsgroups: microsoft.public.inetserver.asp.general
From: abruton <andrebru...@gmail.com>
Date: Fri, 30 Oct 2009 07:50:50 -0700 (PDT)
Local: Fri, Oct 30 2009 10:50 am
Subject: Updating XML Child nodes using Classic ASP Problems
Hi

I am trying to update a child node of an XML file IE Changing the
value.

The XML file looks like this:

<user>
  <firstname>Andre</firstname>
  <lastname>Bruton</lastname>
</user>

Here is my Classic asp code:

users_firstname = "Tristan"  'New code to put in the XML file

  Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
  xmlObj.async = False
  xmlObj.setProperty "ServerHTTPRequest", True
  xmlObj.Load(cURL)
  If xmlObj.parseError.errorCode <> 0 Then
    Response.Write "Error Reaqding File - " & xmlObj.parseError.reason
& "<p>"
  End If

  Set xmlList = xmlObj.getElementsByTagName("user")
  For Each xmlItem In xmlList
    For Each xmlItem2 In xmlItem.childNodes
      a = xmlItem2.nodeName
      if a = "firstname" then firstname = xmlItem2.text
      if a = "lastname" then lastname = xmlItem2.text
    Next
  Next

  If firstname <> users_firstname Then
    Set nodeBook = xmlObj.selectSingleNode("//firstname")
    nodeBook.setAttribute "firstname", users_firstname
    Response.Write nodeBook.getAttribute("firstname")
    xmlObj.save(cDir & cFile)
  End If

  Set xmlObj = Nothing

The problem is that it adds a new section to the XML file instead of
updating the value of firstname from Andre to Tristan. The XML looks
like this:

<user>
<firstname firstname="Andre6">Andre</firstname>
<lastname>Bruton</lastname>
</user>

What is should look like is:

<user>
<firstname>Tristan</firstname>
<lastname>Bruton</lastname>
</user>

Any idea how I can fix this?

Best regards

Andre


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Barrows  
View profile  
 More options Oct 30, 11:36 am
Newsgroups: microsoft.public.inetserver.asp.general
From: "Bob Barrows" <reb01...@NOyahoo.SPAMcom>
Date: Fri, 30 Oct 2009 11:36:34 -0400
Local: Fri, Oct 30 2009 11:36 am
Subject: Re: Updating XML Child nodes using Classic ASP Problems

If you only have a single <user> element, there is no need to do a loop:
just use selectSingleNode:

set usernode = xmlObj.selectSingleNode("//user")

Don't use getAttribute or SetAttribute.
This is an attribute: firstname="Andre6"
This is an element: <firstname>Tristan</firstname>

Untested air code:
set fnamenode = xmlObj.selectSingleNode("//user/firstname")
if fnamenode.nodeValue <> users_firstname then
    fnamenode.nodeValue = users_firstname
end if
Response.Write fnamenode.nodeValue
xmlObj.save cDir & cFile

--
HTH,
Bob Barrows


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
abruton  
View profile  
 More options Oct 31, 12:52 am
Newsgroups: microsoft.public.inetserver.asp.general
From: abruton <andrebru...@gmail.com>
Date: Fri, 30 Oct 2009 21:52:10 -0700 (PDT)
Local: Sat, Oct 31 2009 12:52 am
Subject: Re: Updating XML Child nodes using Classic ASP Problems
Hi Bob

Thank you for the info. I managed to get it working late last night
using the following code...

If firstname <> users_firstname Then
    Set objRoot = xmlObj.documentElement
    Set objField = objRoot.selectSingleNode("firstname")
    objField.Text = users_firstname
    xmlObj.save(cDir & cFile)
End If

Best regards

Andre F Bruton

On Oct 30, 5:36 pm, "Bob Barrows" <reb01...@NOyahoo.SPAMcom> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google