?
Solved

how to merge two XML document?

Posted on 2004-08-09
2
Medium Priority
?
705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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