[xsd-users] Storing individual tree nodes in DB XML documents
Boris Kolpackov
boris at codesynthesis.com
Thu Nov 16 00:00:38 EST 2006
Hi Remsy,
Schmilinsky, Remsy <Remsy.Schmilinsky at ccra-adrc.gc.ca> writes:
> Hi. From the library example:
>
> for (catalog::book::const_iterator bi (c->book ().begin ());
> bi != c->book ().end ();
> ++bi)
>
> I want to save each book in dbxml as a separate document instead of the
> whole catalog. can I convert iterator bi to catalog::book object and
> then use it to save a document in dbxml?
Sure, catalog::book::const_iterator is a standard, STL-like iterator
so you can get to the book by simply dereferencing it:
catalog::book const& b (*bi);
> I am following the dbxml example, it shows how to save the catalog as a
> document instead of a document for each book.
I think this code should do what you want:
// Create a new XML document.
//
XmlDocument doc (manager.createDocument ());
doc.setName ("new.xml");
// Obtain its DOM representation and add the root element.
//
xercesc::DOMDocument& dom_doc (*doc.getContentAsDOM ());
xercesc::DOMElement* e (
dom_doc.createElementNS (
xml::string ("http://www.codesynthesis.com/library").c_str (),
xml::string ("lib:book").c_str ()));
dom_doc.appendChild (e);
// Serialize the object representation to the XML document.
//
*e << b;
// Place the document into the container.
//
container.putDocument (doc, update_context);
hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20061116/daee162e/attachment.pgp
More information about the xsd-users
mailing list