Solved

how to merge two XML document?

Posted on 2004-08-09
2
698 Views
Last Modified: 2012-06-27
I would like to know how to merge two XML document.  I tried using the DataSet.Merge as propose in : http://support.microsoft.com/default.aspx?scid=kb;en-us;308066 but I keep getting the error

The table (NarrowerItems ) cannot be the child table to itself in nested relations.

FILE1.XML:
-------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>
<ItemsHierarchy CatName="">
  <Item Id="1" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Business" ContainsPages="1" />
  <Item Id="93" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Community and living" ContainsPages="1" />
  </ItemsHierarchy>
-------------------------------------------------------------------




FILE2.XML
--------------------------------------------------------------------

  <?xml version="1.0" encoding="utf-8" ?>
<ItemsHierarchy CatName="">
 <Item Id="1" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" CatName="Business">
 <NarrowerItems CatName="">
  <Item Id="2" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Building sites" ContainsPages="1" />
  </NarrowerItems>
  </Item>
 <Item Id="3088" Preferred="true" Default="true" AddedInVersion="1.02" LastUpdatedInVersion="1.02" CatName="Council, government and democracy">
 <NarrowerItems CatName="">
  <Item Id="13" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Information management" ContainsPages="1" />
  </NarrowerItems>
  </Item>
  </ItemsHierarchy>
-------------------------------------------------------------------





My desired output is:
1) ELIMINATION OF DUPLICATE ITEMS
2) Add Missing elements contained in FILE2.XML to the Merged XML output.

 I would like the output to look like this once FILE1.XML and FILE2.XML have been merged:

Output.xml
----------------------------------------------------------------------
  <?xml version="1.0" encoding="utf-8" ?>
<ItemsHierarchy CatName="">
 <Item Id="1" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" CatName="Business">
 <NarrowerItems CatName="">
  <Item Id="2" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Building sites" ContainsPages="1" />
  </NarrowerItems>
  </Item>
 <Item Id="3088" Preferred="true" Default="true" AddedInVersion="1.02" LastUpdatedInVersion="1.02" CatName="Council, government and democracy">
 <NarrowerItems CatName="">
  <Item Id="13" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Information management" ContainsPages="1" />
  </NarrowerItems>
  </Item>
<Item Id="93" Preferred="true" Default="true" AddedInVersion="1.00" LastUpdatedInVersion="1.00" PageExists="true" CatName="Community and living" ContainsPages="1" />
  </ItemsHierarchy>
-------------------------------------------------------------------



PLEASE HELP!
0
Comment
Question by:gaetansavoie
2 Comments
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 500 total points
Comment Utility
You are getting this error as in File2.xml "NarrowerItems" is the child of "Item" Element and it also has a child element by name "Item"

Rename "Item" element under NarrowerItems to NItem(example) and you would be able to read file into dataset

Then, you could loop through records to eliminate duplicate and add new records.

Cheers,
S Sansanwal

0
 
LVL 2

Author Comment

by:gaetansavoie
Comment Utility
Very clever.  Thanks! :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Email Body 4 45
visual Basic Net vs c# net 8 53
Library to convert HTML to PDF. 8 42
Problem to open Excel file 15 35
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now