Evaluating XML data

mattgolsen's picture

I'm banging my head against the wall on this one. I'm not quite sure how to do it.

So I have a XML feed like so:

<mainFeed>
<team>
<field1>1</field1>
<field2>John</field2>
<field3>90</field3>
<field4>80</field4>
<field5>200</field5>
<field6>300</field6>
<field7>9.93</field7>
<field8>4.97</field8>
<field9>130.02</field9>
</team>
<team>
<field1>1</field1>
<field2>Jack</field2>
<field3>80</field3>
<field4>60</field4>
<field5>300</field5>
<field6>200</field6>
<field7>6.5</field7>
<field8>9.5</field8>
<field9>125.50</field9>
</team>
</mainFeed>

And I need to find out things like the average of specific fields, the min, max etc. My problem being is I can't figure out a good way to relate a displayed result with the original substructure. As in, if I find out the highest value for "Field 3" through the entire structure, I need to be able to tell if it comes from "Jack" or "John" teams.

Any ideas?

cwright's picture
Re: Evaluating XML data

javascript would be a good way to handle this, as it can process variable numbers of structures, and provide substructure output. Depending exactly on what you want to accomplish, this could be really simple, or really difficult.

averaging is easy -- just have a field sum for each field of interest, and iterate over each team. For max, you'll want to have a "field leader" var that's initially set to the first team -- then, as you iterate over the teams, you check current field leader's field against the current team's field, and if the current one is better, set the field leader to the current team. After iterating over each team, the field leader vars will be the teams with the largest field value.

Not to be condescending, but this is basic compsci stuff (or intro to algorithms) -- taking a community college intro to programming class would probably one help understand how to tackle these and similar problems. If it's just translating those algorithms into javascript that's tricky, I can totally understand :)

If you've got a full spec for what you need/want done, and some spare change to toss in the donation bin, I can probably whip up a script that performs the above operations (depending on the full spec for what you need analyzed) within an hour or so. you've got my e-mail address.

mattgolsen's picture
Re: Evaluating XML data

Ah not condescending at all. I've never really been interested in programming until I got into QC, so I'm finding all sorts of things I have to learn. QC seems to be a gateway drug for me into programming :D

I'll have to see how much I need this script, it was basically a quick investigation for something I might need, but I'd be more than willing to throw some money your way if need be.