linq to xml ...merge 2 xml docs

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 prettyprinted <span class="pln <span class="kwd Sub<span class="pln mergexml<span class="pun ()<span class="pln
<span class="kwd Try<span class="pln

<span class="com Merge the two Xmls<span class="pln
<span class="kwd Dim<span class="pln addrecipe <span class="kwd As<span class="pln XElement
<span class="kwd Dim<span class="pln query <span class="pun =<span class="pln addingdoc<span class="pun .<span class="pln Descendants<span class="pun (<span class="str "RECIPES"<span class="pun )<span class="pln

addrecipe <span class="pun =<span class="pln <span class="kwd New<span class="pln XElement<span class="pun (<span class="str "RECIPES"<span class="pun ,<span class="pln query<span class="pun )<span class="pln

doc<span class="pun .<span class="pln Element<span class="pun (<span class="str "RECIPES"<span class="pun ).<span class="pln Add<span class="pun (<span class="pln addrecipe<span class="pun )<span class="pln

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

<pre class="prettyprint prettyprinted <span class="pun <?<span class="pln xml version<span class="pun =<span class="str "1.0"<span class="pln encoding<span class="pun =<span class="str "UTF-8"<span class="pun ?><span class="pln
<span class="tag <RECIPES><span class="pln
-<span class="tag <RECIPE><span class="pln
<span class="tag <NAME><span class="pln DADS PIE<span class="tag </NAME><span class="pln <span class="tag <STYLE><span class="pln NEW AGE<span class="tag </STYLE><span class="pln <span class="tag <CHEF><span class="pln DAD<span class="tag </CHEF><span class="pln <span class="tag <DATE><span class="pln 15<span class="tag </DATE><span class="pln -<span class="tag <INGREDIENTS><span class="pln
-<span class="tag <APPLES><span class="pln
-<span class="tag <APPLE><span class="pln
<span class="tag <NAME><span class="pln GALA<span class="tag </NAME><span class="pln
<span class="tag <COLOR><span class="pln PINK<span class="tag </COLOR><span class="pln
<span class="tag <SWEETNESS><span class="pln 3<span class="tag </SWEETNESS><span class="pln
<span class="tag </APPLE><span class="pln -<span class="tag <APPLE><span class="pln
<span class="tag <NAME><span class="pln GRANNY SMITH<span class="tag </NAME><span class="pln
<span class="tag <COLOR><span class="pln GOLD<span class="tag </COLOR><span class="pln
<span class="tag <SWEETNESS><span class="pln 4<span class="tag </SWEETNESS><span class="pln
<span class="tag </APPLE><span class="pln -<span class="tag <APPLE><span class="pln
<span class="tag <NAME><span class="pln Golden Delicious<span class="tag </NAME><span class="pln
<span class="tag <SWEETNESS><span class="pln 4<span class="tag </SWEETNESS><span class="pln
<span class="tag <COLOR><span class="pln gold<span class="tag </COLOR><span class="pln
<span class="tag </APPLE><span class="pln
<span class="tag </APPLES><span class="pln <span class="pln -<span class="tag <SUGARS><span class="pln
-<span class="tag <SUGAR><span class="pln
<span class="tag <NAME><span class="pln CANE<span class="tag </NAME><span class="pln
<span class="tag <COLOR><span class="pln WHITE<span class="tag </COLOR><span class="pln
<span class="tag <PRICE><span class="pln 1.5<span class="tag </PRICE><span class="pln
<span class="tag </SUGAR><span class="pln
<span class="tag </SUGARS><span class="pln
<span class="tag </INGREDIENTS><span class="pln
<span class="tag </RECIPE><span class="pln <span class="pln -<span class="tag <RECIPE><span class="pln
<span class="tag <NAME><span class="pln PETES PIE<span class="tag </NAME><span class="pln <span class="tag <STYLE><span class="pln OLD FASHIONED<span class="tag </STYLE><span class="pln <span class="tag <CHEF><span class="pln MAMA<span class="tag </CHEF><span class="pln <span class="tag <DATE><span class="pln 12<span class="tag </DATE><span class="pln -<span class="tag <INGREDIENTS><span class="pln
-<span class="tag <APPLES><span class="pln
-<span class="tag <APPLE><span class="pln
<span class="tag <NAME><span class="pln MACINTOSH<span class="tag </NAME><span class="pln
<span class="tag <COLOR><span class="pln RED<span class="tag </COLOR><span class="pln
<span class="tag <SWEETNESS><span class="pln 1<span class="tag </SWEETNESS><span class="pln
<span class="tag </APPLE><span class="pln -<span class="tag <APPLE><span class="pln
<span class="tag <NAME><span class="pln GOLDEN DELICIOUS<span class="tag </NAME><span class="pln
<span class="tag <COLOR><span class="pln GOLD<span class="tag </COLOR><span class="pln
<span class="tag <SWEETNESS><span class="pln 2<span class="tag </SWEETNESS><span class="pln
<span class="tag </APPLE><span class="pln
<span class="tag </APPLES><span class="pln <span class="pln -<span class="tag <SUGARS><span class="pln
-<span class="tag <SUGAR><span class="pln
<span class="tag <NAME><span class="pln TRUCKLE<span class="tag </NAME><span class="pln
<span class="tag <COLOR><span class="pln BROWN<span class="tag </COLOR><span class="pln
<span class="tag <PRICE><span class="pln 2.25<span class="tag </PRICE><span class="pln
<span class="tag </SUGAR><span class="pln
<span class="tag </SUGARS><span class="pln
<span class="tag </INGREDIENTS><span class="pln
<span class="tag </RECIPE><span class="pln
<span class="tag </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