Solved

how to merge two XML document?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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