Solved

how to merge two XML document?

Posted on 2004-08-09
2
702 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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