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

Jaws jaws75 at tiscali.it
Fri May 28 03:41:39 EDT 2010


   Thanks for you answer.
   Let's suppose to extend the library example adding in the catalog
   other elements like DVD and CD. So we will change the schema adding
   these new classes of records.
   Let's suppose that you need to add to the original database only the
   new DVDs. You'll have another XML files, we can call the Xml_update,
   that report only the new DVD records.
   How can we manage ths situation? Are we obliged to have the Xml_update
   file with the same structure to the original databse but with the Book
   and CD section empty? Or is it possible to read the file that contains
   only the DVD part?
   Hope I was clear in the explanation.
   Thanks in advance
   Jaws
   Boris Kolpackov ha scritto:

Hi Jaws,

Jaws [1]<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

References

   1. mailto:jaws75 at tiscali.it


More information about the xsde-users mailing list