469,640 Members | 1,563 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,640 developers. It's quick & easy.

Cloning or copying an XMLelement (please help)

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
Nov 16 '05 #1
0 1320

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Cody Manix | last post: by
8 posts views Thread by Tom | last post: by
3 posts views Thread by AVL | last post: by
6 posts views Thread by J Williams | last post: by
4 posts views Thread by =?Utf-8?B?Sm9uIEVsbGlz?= | last post: by
gits
9 posts views Thread by gits | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.