[xsd-users] serialize library objects to ofstream

Boris Kolpackov boris at codesynthesis.com
Fri Sep 22 11:17:38 EDT 2006


Hi Remsy,

Schmilinsky, Remsy <Remsy.Schmilinsky at ccra-adrc.gc.ca> writes:

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

I am glad you managed to answer your own question. You probably
would want to omit specifying the schema (the last line) since
the schemaLocation declaration only makes sense in the root
element. Instead you may want to add the needed attributes to
the root element (see below).


> ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl
>     << "<lib:catalog>" << endl;
>

Note that the resulting XML won't be valid with regards to XML
namespaces because you haven't provided the mapping for prefix
'lib:' in the root element. You can fix this by replacing the
code above with something like this:

ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl
    << "<lib:catalog xmlns:lib=\"http://www.codesynthesis.com/library\">"
    << endl;


If you also want to specify the schema location then it becomes:


ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl
    << "<lib:catalog xmlns:lib=\"http://www.codesynthesis.com/library\"" << endl
    << "  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << endl
    << "  xsi:schemaLocation=\"http://www.codesynthesis.com/library "
    << "library.xsd\">" << endl;


With namespaces streaming becomes a bit tricky.


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/20060922/ab979c0b/attachment.pgp


More information about the xsd-users mailing list