merge 2 xml records

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
okay gurus....
Ive done my due diligence on this one but just cant find the answer Im looking for... I have an XML document that holds recipe records. I would like to merge another xml file with additional recipesinto my master xml document. I have
worked out the code to add the file.... my problem is that I would like to check if the file already exists before I add it to my master xml... heres the code I have to add the new file to the master


<pre class="prettyprint lang-vb Sub mergexml()
Try

Merge the two Xmls
Dim addrecipe As XElement
Dim query = addingdoc.Descendants("RECIPES")

addrecipe = New XElement("RECIPES", query)

doc.Element("RECIPES").Add(addrecipe)

Catch ex As Exception
MessageBox.Show("Error merging Xml Documents")
End Try[/code]
so.... I want to add to this xml document ("doc")
<pre class="prettyprint <?xml version="1.0" encoding="UTF-8"?>
<RECIPES>
-<RECIPE>
<NAME>MAMAS PIE</NAME> <STYLE>OLD FASHIONED</STYLE> <CHEF>MAMA</CHEF> <DATE>10</DATE> -<INGREDIENTS>
-<APPLES>
-<APPLE>
<NAME>Gala</NAME>
<QUANTITY>2</QUANTITY>
<COLOR>pink</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE> -<APPLE>
<NAME>MACINTOSH</NAME>
<QUANTITY>3</QUANTITY>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE> -<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<QUANTITY>4</QUANTITY>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES> -<SUGARS>
-<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE> -<RECIPE>
<NAME>DADS PIE</NAME> <STYLE>NEW AGE</STYLE> <CHEF>DAD</CHEF> <DATE>15</DATE> -<INGREDIENTS>
-<APPLES>
-<APPLE>
<NAME>GALA</NAME>
<COLOR>PINK</COLOR>
<SWEETNESS>3</SWEETNESS>
</APPLE> -<APPLE>
<NAME>GRANNY SMITH</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE> -<APPLE>
<NAME>Golden Delicious</NAME>
<SWEETNESS>4</SWEETNESS>
<COLOR>gold</COLOR>
</APPLE>
</APPLES> -<SUGARS>
-<SUGAR>
<NAME>CANE</NAME>
<COLOR>WHITE</COLOR>
<PRICE>1.5</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE> </RECIPES> [/code]
this xml document.... but only the distinct elements

<pre class="prettyprint <?xml version="1.0" encoding="UTF-8"?>
<RECIPES>
-<RECIPE>
<NAME>DADS PIE</NAME> <STYLE>NEW AGE</STYLE> <CHEF>DAD</CHEF> <DATE>15</DATE> -<INGREDIENTS>
-<APPLES>
-<APPLE>
<NAME>GALA</NAME>
<COLOR>PINK</COLOR>
<SWEETNESS>3</SWEETNESS>
</APPLE> -<APPLE>
<NAME>GRANNY SMITH</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE> -<APPLE>
<NAME>Golden Delicious</NAME>
<SWEETNESS>4</SWEETNESS>
<COLOR>gold</COLOR>
</APPLE>
</APPLES> -<SUGARS>
-<SUGAR>
<NAME>CANE</NAME>
<COLOR>WHITE</COLOR>
<PRICE>1.5</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE> -<RECIPE>
<NAME>PETES PIE</NAME> <STYLE>OLD FASHIONED</STYLE> <CHEF>MAMA</CHEF> <DATE>12</DATE> -<INGREDIENTS>
-<APPLES>
-<APPLE>
<NAME>MACINTOSH</NAME>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE> -<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES> -<SUGARS>
-<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
</RECIPES> [/code]
so.... essentially, Im looking to merge these files and exclude the file that already exists.... (in this case "DADS PIE")

Thanks

Pete

View the full article
 
Back
Top