473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 1518

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Parham | last post by:
Hello, I have an inherited class from XmlElement with this name: XmlElementCF I have added a function in XmlElementCF that returns a XmlNode, the node type is Element. I can cast the returned node...
1
by: Cody Manix | last post by:
iam trying to program a copy constructor that is able to create a bitwise copy of its argument: MyClass { int a; // lots of different fields goes here float x; MyClass (MyClass my) {
8
by: Tom | last post by:
I've a problem. I want to clone an object having a list of other objects (and so on :/). Do you know any other way than ICloneable.Clone() implementation for all classes in the way? Help..
3
by: AVL | last post by:
Hi, I've a query in cloning. How cloning is different from creating a new instance of an object.? I suppose cloning also creates a new object and copies the exisitng object's data. Where and when...
6
by: J Williams | last post by:
I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application to create a new HTML document by cloning nodes. The function below is called from the axWebBrowser1_DocumentComplete...
3
by: Coleen | last post by:
Hi all :-) I have a datatable that I need to clone completely except for 1 column - I need to replace the contents of this 1 column with the contents from another datatable that has the exact...
4
by: =?Utf-8?B?Sm9uIEVsbGlz?= | last post by:
Hi All, I want to implement an 'generic' undo by placing a copy of a control in a stack using System.Collections.Generic.Stack. Basically this way I don't need to know if a user has edited text...
3
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found here: http://www.sendspace.com/file/mjyocg (Word...
9
gits
by: gits | last post by:
This short article introduces a method that may be used to create a 'deep-copy' of an javascript object. You might ask: 'Wherefore do we need this?' ... Answer: 'Only variable-values of the basic...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.