[xml] Generating XML from Schema definitions


I'm a relative XML newbie. It seems a simple concept with lots of confusing
terminology around it.

I've been acquainting myself with XML and gradually getting to know
libxml2 and the functionality it provides, and I'm wondering if it's
able to do what I want.

Basically, I have a large document schema spread across several xsd files
which are imported into each other. I know xsd is used primarily for
validation, but I would like to use the schema definition to generate a
valid XML document from my data. I think this is basically how things
work in the java world with xmlbeans, etc where you can generate your
class definitions from the xsd files and then populate them with set

It seems I could read the individual schemas files as documents and build
up an overall schema definition myself, but xmlSchemaParse seems to do
that for me so it would be silly not to use it.

I've managed to suck in the top level schema file and it imports all the
sub-schemas fine, but it seems to store it all obscurely internally, and
I'm not familiar enough with the API to know if what I want to do is
possible. I can grunge around with a debugger and see where things are
stored but many of the data structures aren't exposed and the imported
schemas don't seem to be linked to the main one in any way that allows
me to traverse the xsd "document", look up imported schemas and types
to build my xml output.

I would envisage being able to traverse the schema and check the xpath
of each element against a mapping into my own data which would allow
me to populate/generate the output as xml. I don't really want to just
manually code to a specific xml schema since I don't have control of
the schema, hence my desire to programmatically generate it based on the
schema files which would be read in up front.

Can anyone tell me if this is possible with libxml2 and give me a rough
outline of how to go about it, which APIs I should look at or example
programs which do a similar thing.



Callum Gibson @ home

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