"Martin Honnen" <mahotrash@xxxxxx> wrote in message
news:ed4q9F1bJHA.4500@xxxxxx
> Tom wrote:
>
>> You think this would be easy, but it's killing me. I have 2 XElement
>> objects. Both consist of the same schema, and all I want to do is merge
>> the 2 w/o having any duplicates. Is there an easy way to do this? I've
>> tried Linq, and the old XML API, but have been unsuccessful with both.
>> If somebody has an example in Linq, that would be awesome. >
> Well how exactly do you want to identity duplicates? Based on certain
> element or attribute value like an id element or attribute? Does the
> schema define an id attribute or a key elements?
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ Well,
Here's how I build an XML file ...
public void RecursivelyBuildDescendentTree()
{
XElement OriginalPerson =
new XElement ("Person",
new XElement ("Name", "Bob"));
XElement Child1 =
new XElement ("Person",
new XElement ("Name", "John"));
XElement Child2 =
new XElement ("Person",
new XElement ("Name", "Jane"));
XElement Girlfriend1 =
new XElement ("Person",
new XElement ("Name", "Sally"));
XElement Girlfriend2 =
new XElement ("Person",
new XElement ("Name", "Kelly"));
}
public void test()
{
XElement root = new XElement("Root");
XElement rootPerson = RecursivelyBuildDescendentTree();
}
I'm not building a family tree, but it's the same idea. The tree starts out
with a person, and each person can have 0 or more children, and 0 or more
girlfriends. I would basically want to merge 2 files like this based on the
person's name. I have no xsd file, the schema is built right into the code
(as shown above). I know I should be verifying it, but I'm not right now.
I'm just looking to get this working first.
Right now I'm working on adding some type of merge method that will take 2
XElement structures, and manually go through 1 and determine if a person is
not in the other. If not, then it will add the person and all of that
person's children and girlfriends.
Seems like there is a better way though. I also feel like this is going to
be really slow when I'm finished.