[xsd-users] Serializing ...
Boris Kolpackov
boris at codesynthesis.com
Mon Oct 2 12:01:59 EDT 2006
Hi Jason,
Jason Wang <jwang at saic-asd.com> writes:
> I am new to XSD and I like it very much so far.
Great!
> I had some minor issues on serializing to ostream (and the
> operator<<(...)). I am not sure if it is by design or is it a bug. But
> when streaming, it crashes when a required element is not set (or null).
Hm, I wonder how you managed to construct an object with a required
element not set? By default, XSD-generated constructors will force
you to supply all required elements and attributes. Unless, of course,
you are using the --generate-default-ctor option which will make XSD
always generate default constructors which leave required members
uninitialized.
> I guess it is by design. If so, I wonder if there is way to relax
> this condition by set some parameters at code generation or at run time.
> I personally feel a warning message is more user friendly than
> crashing the code if a required element is not set.
It is not clear to me how useful that would be. The resulting XML will
be invalid: you won't be able to validate it against the schema nor
parse it back to the in-memory representation using the XSD-generated
code. Because of this we've decided to leave it as an application logic
error just like dereferencing null pointer is.
> Also in order to stream, one needs to set the following lines first:
>
> xml_schema::namespace_infomap map;
> map["pos"].name = "...";
> map["pos"].schema = "...";
>
> It would be more user friendly to me if a default value is provided.
> After all those info is readily available at code generation.
I agree the namespace name and prefix information can be inferred
from the schema. However, I don't think it is a good idea to use
the same schema file name as the one being compiled. What if you
are passing an absolute path such as /tmp/my-schema.xsd? You
don't want '/tmp/my-schema.xsd' in you XML instances. We could
probably strip everything except the file name... I don't see a
reason why we can't do that. I will add it to our TODO list,
thanks for the suggestion!
thanks,
-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/20061002/adcd43be/attachment.pgp
More information about the xsd-users
mailing list