[xsd-users] Need help: how to merge multiple xml files

JW jianwei.z at gmail.com
Fri Oct 8 10:52:26 EDT 2010


Hi Boris,

Thank you for your reply.

All XML files shared the same schema.  Here is an example of what I want to
do with the merging.

1. full_elem.xml will have all elements ever required.  Say, <configs> is
the root.

<configs>
  <config id="1" name="config1">
    <threshold>10</threshold>
    <duration>60</duration>
  </config>
  <config id="2" name="config2">
    <threshold>20</threshold>
    <duration>120</duration>
  </config>
</configs>

2. override_elem.xml will have part of elements that their elements will be
overwritten.

<configs>
  <config id="1">
    <threshold>100</threshold>
  </config>
  <config id="2">
    <duration>180</duration>
  </config>
</configs>

After the merging, the final full_elem.xml would look like the following:

<configs>
  <config id="1" name="config1">
    <threshold>100</threshold>
    <duration>60</duration>
  </config>
  <config id="2" name="config2">
    <threshold>20</threshold>
    <duration>180</duration>
  </config>
</configs>


Thanks,
JW



On Fri, Oct 8, 2010 at 10:49 AM, Boris Kolpackov <boris at codesynthesis.com>wrote:

> Hi,
>
> JW <jianwei.z at gmail.com> writes:
>
> > I have been reading the manuals and wiki but could not find a solution
> for
> > this kind of merging.
>
> There is no way to automatically merge two object models. The process is
> not well defined (i.e., are the new values added at the beginning or at
> the end, at what depth in the tree, what happens to duplicates, etc.,
> etc).
>
> Perhaps if there is some regularity in your XML documents, then some
> schema-specific merging can be done. For example, if your document has
> the following structure:
>
> <position>
>  <measure x="1.1", y="2.1"/>
>  <measure x="1.0", y="2.1"/>
>  <measure x="1.1", y="2.0"/>
> </position>
>
> Then it should be easy to come up with a simple merge algorithm. Can you
> tell us more about your document structure? Maybe also show some examples
> of the merges that you want to achieve.
>
> Boris
>


More information about the xsd-users mailing list