I need help merging two XML files (eg master.xml and document_XXX.xml). Essentially, we have a simgle "master.xml" file which contains all the possible nodes, but it evolves as clients want updates. We also have old XML files with data but they are missing nodes when compared to the master.xml. The nodes in the documents are always a subset of the master.xml
In the example, please note: The master.xml has /keywords/keyword/@type but doc#35 does not. The master has a relatedLinks node but document does not. And the master.xml has one "dummy" page node but doc#35 has 2 actual pages.
So you can think of the problem in two ways. Either you populate the master.xml with the data from the document, repeating nodes as necessary. Or given document #35, we need to append all the missing nodes and attributes.
BTW, I've been working on this problem for several days... I don't know if that means it's difficult or I'm just an idiot (or both) but I've certainly tried before asking the experts.
========== Document master template ===========
<document id="" status="">
<title><![CDATA[]]></title
>
<date></date>
<authors>
<author id="">
<firstName></firstName>
<lastName></lastName>
</author>
</authors>
<keywords>
<keyword id="" type=""></keyword>
</keywords>
<content>
<page>
<subTitle><![CDATA[]]></su
bTitle>
<subBody><![CDATA[]]></sub
Body>
<subFooter><![CDATA[]]></s
ubFooter>
</page>
</content>
<relatedLinks>
<link>
<text></text>
<url></url>
<link>
</relatedLinks>
</document>
========== Document #35===========
<document id="35" status="1">
<title><![CDATA[Title of the document.]]></title>
<date>12/31/2004 5:00PM</date>
<authors>
<author id="5">
<firstName>John</firstName
>
<lastName>Doe</lastName>
</author>
</authors>
<keywords>
<keyword id="3">Blue</keyword>
<keyword id="5">Green</keyword>
<keyword id="7">Red</keyword>
</keywords>
<content>
<page>
<subTitle><![CDATA[Title of page #1]]></subTitle>
<subBody><![CDATA[Body of page #1]]></subBody>
<subFooter><![CDATA[Footer
of page #1]]></subFooter>
</page>
<page>
<subTitle><![CDATA[Title of page #2]]></subTitle>
<subBody><![CDATA[Body of page #2]]></subBody>
<subFooter><![CDATA[Footer
of page #2]]></subFooter>
</page>
</content>
</document>
========== Merged Document Output ===========
<document id="35" status="1">
<title><![CDATA[Title of the document.]]></title>
<date>12/31/2004 5:00PM</date>
<authors>
<author id="5">
<firstName>John</firstName
>
<lastName>Doe</lastName>
</author>
</authors>
<keywords>
<keyword id="3" type="">Blue</keyword>
<keyword id="5" type="">Green</keyword>
<keyword id="7" type="">Red</keyword>
</keywords>
<content>
<page>
<subTitle><![CDATA[Title of page #1]]></subTitle>
<subBody><![CDATA[Body of page #1]]></subBody>
<subFooter><![CDATA[Footer
of page #1]]></subFooter>
</page>
<page>
<subTitle><![CDATA[Title of page #2]]></subTitle>
<subBody><![CDATA[Body of page #2]]></subBody>
<subFooter><![CDATA[Footer
of page #2]]></subFooter>
</page>
</content>
<relatedLinks>
<link>
<text></text>
<url></url>
<link>
</relatedLinks>
</document>
Start Free Trial