I've run into a problem with a recursive algorithm.
Basically, it grabs a tree, and creates premutations based off it.
For example:
Suppose you have you sell shoes in two colors (Black, Brown) and two
sizes (Large, Small).
My algorithm will run through a special XML tree (not a regular tree,
but it works about the same), and create premutations based off it
(saving it in an XML document). I'm dealing with two incompatible
XML-based systems, where one type is converted to the other.
So the output would be:
Black Small
Black Large
Brown Small
Brown Large
Additionally, I need the setAttribute method, so I need to use
XMLElements (correct me if I'm wrong).
What should happen is an element should be cloned or copied, then
modified.
Supposing I throw in "GH Bass" as a type of shoe. It should clone "GH
Bass" twice, giving me two elements:
GH Bass Black
GH Bass Brown
Then the algorithm calls recursion on those elements, giving:
GH Bass Black Small
GH Bass Brown Small
GH Bass Black Large
GH Bass Brown Large
Instead, I'm getting nothing.
Here some code:
<Snip>
private System.Collections.ArrayList
BuildVariants(System.Xml.XmlNodeList nl, System.Collections.ArrayList
v)
</Snip>
<Snip>
System.Xml.XmlElement can =
(System.Xml.XmlElement)(((System.Xml.XmlElement)(v[x])).Clone()); //v
is an ArrayList
("can" is modified)
</Snip>
<Snip>
rx.Add(can); //rx is an ArrayList, "can" is added to rx
</Snip>
<Snip>
variantup.AddRange(BuildVariants(nl[i].SelectNodes("Choice"), rx))
//variantup is an ArrayList
</Snip>
<Snip>
return variantup;
</Snip>
<Snip>
//This part appends the final results to the document
for(int h = 0; h < variantbuild.Count; h++)
{
XMLProduct.AppendChild((System.Xml.XmlElement)(var iantbuild[h]));
}
</Snip>
Something happens when the element is cloned. Running the algorthim
(modified) with non-cloned elements works fine. Any help? I'm dying
here.
Any alternative methods for cloning or copying? Elements are added and
attributes are modified with each pass.
Thanks,
Ryan