[xsd-users] how to create en xml file

Boris Kolpackov boris at codesynthesis.com
Mon Nov 27 10:23:14 EST 2006


Hi Thierry,

LETELLIER Thierry <thierry.letellier at capgemini.fr> writes:

> I m a new xml/xsd user
> Someone have generate C++ sources from an xsd schema
> He use it to read an xml file
> and i have to use the sources and the schema to create this file
> But i don't understand How it work at all
>
> First : how can i open the stream
> Second : I have the write a vector of objets how can i do that

There is the library example in examples/cxx/tree/library that shows
how to do what you want. Normally you would create an empty top-level
instance that represents your document. In case of the library example
it would be catalog (which is a sequence of books):

catalog c;

Then you populate this instance with data, e.g., by creating and adding
one or two books:

book b (679776443,            // ISBN
        title ("Dead Souls"), // Title
        genre::philosophy,    // Genre
        "DS");                // ID

b.author ().push_back (author ("Nikolai Gogol", "1809-03-31"));

c.book ().push_back (b);

Then you open a stream (this could be pretty much any stream, a file
stream, a string stream, etc.):


std::ofstream ofs ("result.xml");


Finally, you serialize the in-memory representation to the stream:

xml_schema::namespace_infomap map;

map["lib"].name = "http://www.codesynthesis.com/library";
map["lib"].schema = "library.xsd";

catalog_ (ofs, c, map);


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/20061127/41c1ed23/attachment.pgp


More information about the xsd-users mailing list