[xsd-users] XSD serialize to and from wstring
Boris Kolpackov
boris at codesynthesis.com
Thu Oct 16 05:39:50 EDT 2008
Hi George,
George Vassilakes <george at sbdev.net> writes:
> Another question I have is if its possible to get xsd to generate c++
> header files describing the schema so when the application runs it does
> not need to find the .xsd file on the disk. Is it possible to supply
> this file from memory?
> What I would like to do is to get my executable running without
> requiring to find the .xsd files on some location on the disk.
There are two ways you can achieve this. The first is to embed the
schema into your application as a text file or string and then
load it before parsing XML documents. This approach is described
in the following posts to xsd-users:
http://www.codesynthesis.com/pipermail/xsd-users/2006-September/000536.html
http://www.codesynthesis.com/pipermail/xsd-users/2006-September/000540.html
This approach gets complicated if you need to embed schemas with
imports/includes. The easiest way to handle this situation is to
use the binary representation of the schema grammar instead of the
text representation. Xerces-C++ support storing pre-parsed schema
grammar (all the imported/included schemas as one grammar object)
in a binary format which you can then embed into your application
and load at runtime. It has an extra benefit of being quite a bit
faster than parsing the actual schemas. The following article on
IBM developerWorks has more information on the binary grammar
serialization feature:
http://www-128.ibm.com/developerworks/webservices/library/x-xsdxerc.html
It is also possible to use textual representation in multi-schema
case. For this to work you will need to implement XMLEntityResolver
interface which, if provided, gets called to resolve various
external entities, including included/imported schema files.
In your implementation you could search a map of embedded files
and return MemBufInputSource for each.
Boris
More information about the xsd-users
mailing list