Re: [xml] Generate XML using XSD

On 14Oct08 13:06, Prabhuram K wrote:
}This sounds great. Can you please pass on the callback implementations.

Here is an example of how you could implement callbacks for the template
and document generation functions. It's up to you how far you abstract
things. This example has lots of stuff hard-coded. In my use at work,
the data and translator callbacks are data-agnostic, and the arrays of
literal values and data accessor functions are the ones that know about
the internal data structures of whatever data you're trying to write out
as xml. That's partly why my example is constructed the way it is. You
could just as easily perform all data access in the one callback data
function, and if you have no abstract types or literals you don't even
need a translator callback with anything in it.

In the attached zip file:
foo.xsd is a simple schema definition
foo.xml is an example of a compliant document.
trans.c is some sample code for generating a different compliant document.
output.xml is the actual output from trans.

I compiled trans.c like this:

$ gcc -g `xml2-config --cflags --libs` -o trans trans.c

Note, there are features in foo.xml you can't achieve (yet) with the
schema translation code. In particular, you can't defer the resolution
of abstract types at the template generation stage. If you want to have
documents with different resulting types you need to define separate templates.
This is noted in xsdtranslate.c with XXX along with lots of other gotchas.

Hopefully this provides you with a starting point. Note the header has
a reasonable about of doco in it too.



Callum Gibson @ home

Description: Zip archive

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]