Solved

how to merge two XML document?

Posted on 2004-08-09
2
699 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
ID: 11758929
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
ID: 11761468
Very clever.  Thanks! :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

14 Experts available now in Live!

Get 1:1 Help Now