• 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
            Else
                  Call parentNode.setAttribute(NodeName, NodeValue)
            End If
      End Sub
0
slamhound
Asked:
slamhound
  • 4
  • 4
1 Solution
 
deighcCommented:
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)
0
 
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.
0
 
deighcCommented:
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.
0
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.

<pack>
<PackID>29</PackID>
<PackGroupID>1</PackGroupID>
<PackName>Bag Tag Aeroplane</PackName>
<PackActive>1</PackActive>
<Shipping>0</Shipping>
<CreatedStamp>2003-07-04T09:45:20</CreatedStamp>
<UpdatedStamp>2004-05-10T13:14:03</UpdatedStamp>
<UpdatedUserID>4518</UpdatedUserID>
<IsMultiPack>0</IsMultiPack>
<rowguid>{B84D3F28-949D-425D-8C0E-967EDA914812}</rowguid>
<PackGroupID>1</PackGroupID><PackGroupName>Bag Tags</PackGroupName>
<rowguid>{1958DD50-7157-45BD-AC3A-E61B76C10B27}</rowguid>
<CostID>4</CostID>
<RegionID>1</RegionID>
<PackID>29</PackID>
<DefaultCost>3.5</DefaultCost>
<StockItem>1</StockItem>
<ReStockLvl>0</ReStockLvl>
<StockLvl>0</StockLvl>
<ReStockUserID>0</ReStockUserID>
<CreatedStamp>2003-07-04T10:04:15</CreatedStamp>
<UpdatedStamp>2004-10-06T12:50:15</UpdatedStamp>
<UpdatedUserID>4525</UpdatedUserID>
<rowguid>{407B0E3D-BF43-4A8E-ABA3-738AA2431468}</rowguid>
</pack>~~

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.
0
 
deighcCommented:
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

0
 
slamhoundAuthor Commented:
Much better! Almost there!

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

Eg.
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?
0
 
deighcCommented:
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.
0
 
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.

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21410330.html
0

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