Christopher Shrout

Greenhorn
+ Follow
since Jul 23, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Christopher Shrout

I will need at least a "3-dimensional" array in order to create multiple "series" to be charted on an xy line graph. I understand the limitations of Java and that one can only create "an array of arrays". How do I "redimension" or re-instate an array to hold more entries?

Could someone provide me with a good example of creating a "multi-dimensional array" (3 dimensional would be quite useful!). Things in VB always seemed a little more straightforward...
11 years ago

Bear Bibeault wrote:jQuery used to support XPath but no longer does.

I've had no problem using normal jQuery selectors when dealing with an XML DOM.



As I'm quite green, how could I accomplish basically the same thing (creating a sum value) by using Jquery? I've looked through the w3schools Jquery tutorials, but it almost appears as though it was designed to manipulate items on the page rather than glean data.

g tsuji wrote:Like this.

ps But I do not endorse any mis-use of document.write().>



Thank you so much!!! I was totally missing the fact that a) I needed "parseFloat" and b) I needed to parse both the node value *and* the variable value each time. Amazing.

It seems that while the Firefox code has (sum(//price)) the I.E. code does not... is that a difference between the browsers? Are there certain XPath expressions that will not work with I.E.? Thank you again, huge relief.
Very true... the "parseDouble()" command doesn't seem to be working... I get an "Object Expected" error at line 33... There *must* be a way to sum these data in these nodes and then average them...

Ok here is some "revised" code. It appears to be concatenating strings instead of actually performing any math: (Lines 32-37)



I get this result:

Sum: 030.0029.9949.9939.95



Plain english: Sum: 030.00, 29.99, 49.99, 39.95. Clearly it is concatenating and not performing any type of arithmetic. Something to do with the "selectNodes()" command...

Paul Clapham wrote:So if I understand the sequence of events correctly, when you used XPathResult.ANY_TYPE then your Javascript code ran correctly and produced the output you expected, but when you used XPathResult.NUMBER_TYPE then you got a message saying "'XPathResult' is undefined"?



It was set to "ANY_TYPE" initially and I changed it to "NUMBER_TYPE" but the result was the same - still "XPathResult is undefined". Sorry that I'm horribly green on this, just picked it up last week. Perhaps I need to iterate and add each individual value to create the sum. I've tried creating additional variables and throwing them in the for loop but it didn't help much... I'll hack something together real quick.
I'll blurt my most recent code attempt onto here: (Go about halfway down for the line I added)



I *believe* that simply running "sum(/price)" should return the results that I'm looking for... but I believe I am putting it into the wrong spot... That code is returning the following error in IE:

Message: 'XPathResult' is undefined



If I can fix my syntax issue then I'm sure I can play around with the other operators like Average etc. Apparently the "selectNodes" command does not return "number" values, only strings. Hence the reason why I am *attempting* to beat a different code snippet into submission.
Howdy all! Posting my question here as well since this seems to be an awesome community!

Using the following example XML file: W3Schools Books.xml I am trying to create an XPath string that will provide:

1) A sum of all "Price" fields in the document

2) An "Average" value of all the prices

There is sample code already present in their "tryit" section which I am trying to adapt: W3Schools example code
I've adapted their original path to display prices, but I cannot seem to get the "Sum" operator to work... Any help would be greately appreciated!