I’m developing a flash application, and one of the things it has to do is take some user input, compare it to a number of possible matches in an XML file, and return the closest match.
At the moment, I’m putting the user input into an array, looping through it, then looping through the XML and keeping track of how many nodes match in a separate array.
That all sounds very confusing so here’s an example:
The XML is structured like this:
<item id="A">
<stage age="1 Week">
<property1>1</property1>
<property2>AC</property2>
</stage>
<stage age="2 Weeks">
<property1>1</property1>
<property2>AF</property2>
</stage>
</item>
<item id="B">
<stage age="1 Week">
<property1>3</property1>
<property2>AG</property2>
</stage>
<stage age="2 Weeks">
<property1>2</property1>
<property2>AN</property2>
</stage>
</item>
There are about 50 ‘items’ in the XML, and each one has about 30 ‘stages’. I’m looking to find the ‘age’ that best matches the user input.
The user is inputting ‘property1’ and ‘property2’. The loops then take the user input for item ‘A’, check if it matches stage 1, and if it does it stores that information in a results array. Then it does this for all the other stages, before moving on to item ‘B’.
As you can imagine this is taking quite a while, and I’m convinced that this is probably the least efficient way of doing it. Does anyone have any suggestions of a more efficient way of calculating this stuff? I’m open to anything, even restructuring the XML if necessary. The only requirement is that users put in the 2 properties for each item, and the program returns the best matching age.
I know this is all ridiculously confusing, so if any further clarification is needed, just ask.
Thanks in advance to anyone patient enough to read all this!
P.S. For reference, this is the function in question:
for (var i:Number = 0; i < dataEntry.inputArray.length; i++) {
if (dataEntry.inputArray* != "-") {
for (var j:Number = 0; j < 31; j++) {
if (mainXML..item*.stage[j].property1.text() == dataEntry.inputArray*) {
dataEntry.matchArray[j] += 1;
}
}
}
if (dataEntry.property2Input* != "-") {
for (var p:Number = 0; p < 31; p++){
if (mainXML..item*.stage[p].property2.text() == dataEntry.property2Input*) {
dataEntry.matchArray[p] += 1;
}
}
}
}