Use XML Schema to Generate XML Documents
-
I have an xml schema and an example xml document based on those schema. What I would like to do is create a way to read the schema and pattern document creation that would produce a valid xml document. So the schema directs what objects can be created.
Here is the schema:
schemaHere is an example doc:
exampleI would like to use Qt xml libraries if possible. One of the problems is this is so domain specific, and many of the documents rely on external sources of information. There are lots of namespace entries in that demo xml. I am just not sure if what I want to do is possible. I have found schema to C++ converters, but what happens if the schema changes in the future? I would like whatever solution I come up with to be dynamic and possibly support multiple versions of the schema.
The main thing is I cannot get my head around how to use the schema in anything but a validation use case. I get that part. I realize I will have to make assumptions about datatypes, and thankfully there are datatypes already defined in documents related to this schema.
-
Okay, I think I found the tool I was looking for.
In Eclipse with the Web plugin you can literally right click on an xsd file and tell it to generate an xml file that, once it is generated you can add namespaces to the file. From there you can edit the file using a structured editor to add elements that correspond to the schema and various namespaces you added. This allows a structured creation of an xml file from the schema(s) you have selected. Eclipse will also keep validating against the schema so you will show errors if you enter in an incorrect node.So while initially I was looking for a programming solution, I was really looking for a suitably featured xml tool. I am sure there are others out there. I think visual studio has some tools for this.