• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

XML/XSL Values Not Updating

I have the below code that is generating no erros but not updating any values either.
What am I doing wrong?
                        myStr = "/root/packs/pack[PackID=" & arPack(Loopy) & "]"
                        response.Write myStr & " " & arPack(Loopy) & " = " & arPrice(Loopy) &  "<br>" '<== This line shows good data
                        response.Write oXML.selectSingleNode(myStr).getAttribute("DefaultCost") & " XX <br>"  '<== Blank

                        Call oRS2XML.setValue(oXML.selectSingleNode(myStr), "DefaultCost", arPrice(Loopy))
                        response.Write oXML.selectSingleNode(myStr).getAttribute("DefaultCost") & " XX <br>"  '<== Blank

(I can't change this subroutine)

      Public Sub setValue( parentNode, NodeName, NodeValue )
            If IsNull(NodeValue) then Exit Sub
            'response.write "," & NodeName & "," & NodeValue & "<br>"
            If gElementCentric Then
                  Dim newNode
                  Set newNode = parentNode.ownerDocument.createElement(NodeName)
                  newNode.text = nodeValue
                  Call parentNode.appendChild(newNode)
                  Set newNode = Nothing
                  Call parentNode.setAttribute(NodeName, NodeValue)
            End If
      End Sub
  • 4
  • 4
1 Solution
Are you sure that the attribute "DefaultCost" actually has a value?? Maybe it's empty.

Try this and see what's in the XML node:

response.Write oXML.selectSingleNode(myStr).xml

(You'll have to view the page source to view the output)
slamhoundAuthor Commented:
I've added:
response.Write oXML.selectSingleNode(myStr).xml & "~~"
Call oRS2XML.setValue(oXML.selectSingleNode(myStr), "DefaultCost", arPrice(Loopy))
response.Write oXML.selectSingleNode(myStr).xml & "~~"

Both are comming up blank.
Are you sure? You'll have to view the page source to see the results because it should output an entire XML tag which your browser will ignore.

I don't think it's possible for this to have no output. You're trying to write out the entire XML of a node. If the node doesn't exist then you'll get an error when you try and output it's .xml property. Assuming you're not getting any errors then there must some output.

Make sure (for now anyway) you're not using any On Error Resume Next error catching.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

slamhoundAuthor Commented:
Sorry, I lost your output in all my debuggin output. Here is what you were looking for:

<br>/root/packs/pack[PackID=29] 29 = 10<br> XX <br> <== My debugging stuff that shows we have packid 29 and that we have a value 10 that I want to insert into the DefaultCost.

<PackName>Bag Tag Aeroplane</PackName>
<PackGroupID>1</PackGroupID><PackGroupName>Bag Tags</PackGroupName>

I'm looping through values so I grabbed what I thought was just the first set of information. You will notice duplicate information because the data is drawn from a query using inner joins and selected everything from both/all tables.

I can't find any On Error stuff. I have inherited this code so can't be certain.
OK, I think I understand your problem. Maybe...

As far as I can tell the function setValue() is working correctly.

The only thing that is wrong is your debug code :-)

This line here is wrong:

response.Write oXML.selectSingleNode(myStr).getAttribute("DefaultCost")

This code has two parts: the selectSingleNode part and the getAttribute part

What the first part does, based on your XPath query (ie. the value of myStr), is select a a <pack> node whose <PackId> child node has a value of 29.
This selectSingleNode method returns an XML node object - the <pack> node.

The second part (getAttribute) attempts to read the value of an attribute called "DefaultCost" from the node (ie. <pack>).
But you can clearly see that <pack> has no atttributes, only child nodes.

What you actually want to do is read the text property of the <DefaultCost> child node.
The simplest way to do this is to change your XPath query to select the <DefaultCost> node then simply read it's text property:

' Change the XPath query to select the <DefaultCost> node
myStr = "/root/packs/pack[PackID=" & arPack(Loopy) & "]/DefaultCost"
' Read the text property of this node.
response.Write oXML.selectSingleNode(myStr).text

slamhoundAuthor Commented:
Much better! Almost there!

The value of DefaultCost is being added together like a string instead of being assinged the value

Originally DefaultCost = 3.5
I set DefaultCost to 10 and I get 3.510
I set DefaultCost to 10 again I get 3.51010
I set DefaultCost to 10 again I get 3.5101010

How do I get Default cost to accpet the value rather than append it?
This must be happening somewhere else in your code but I can't see how that would be happening from the code you posted initially.

My guess is that (somewhere) you're extracting the current value out of the node. This value will be a string. You're then using the "+" operator to add the new value. But because the value is a string the new value is appended rather than mathematically added. Confusingly VBScript lets you use either "&" or "+" as a string concatenator.
slamhoundAuthor Commented:
Thanks Deighc. You have answered the question well. I still need more help so I've posted another question here that you may also be able to answer.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now