[xsde-users] Load multiple xml files and combine the data

Boris Kolpackov boris at codesynthesis.com
Thu May 27 11:16:25 EDT 2010


Hi Jaws,

Jaws <jaws75 at tiscali.it> writes:

> I need to add some new data coming from another xml file that will  
> define some other data with the same schema.
>
> How can I do this mainteining the previous data and adding the new 
> ones?

This depends on what the schema looks like at the point where you
want to add new data. The most likely case will probably be adding
entries from one sequence of elements to another. For instance,
copying books from one library document to another in the 'library'
example (see examples/cxx/tree/hybrid/library/).

In case of the 'library' example, the book type is variable-length
so if you want to make a copy of it to insert into another document
then you will need to do it manually (if the element type that you
want to copy if fixed-length then you can just copy it with a copy
constructor). However, there is a shortcut if you don't need the
source document after this operation. In this scenario, instead of
copying elements, you can move them from one object model to another
by detaching each one from the source document and attaching it to 
the destination document. Here is how this can be done for the library
example:

auto_ptr<catalog> src = ...
auto_ptr<catalog> dst = ...
    
catalog::book_sequence& src_books (src->book ());
catalog::book_sequence& dst_books (dst->book ());

for (catalog::book_iterator i = src_books.begin ();
     i != src_books.end ();
     ++i)
{
  book* b = src_books.detach (i);
  dst_books.push_back (b);
}

This code fragment removes all the books from src document and adds
them at the end of the dst document.

Boris



More information about the xsde-users mailing list