views:

4853

answers:

5

I was wondering if there's a way I can automate the generation of XML files from XSD schemas given that I have the data and the labels. I'd like to do this in python/java. It seems very possible, yet I can't find any library that allows me to do this. I'm looking for a fairly quick solution.. Any ideas?

See also: how-to-generate-sample-xml-documents-from-their-dtd-or-xsd

+1  A: 

JAXB works fantastic for generating classes from xsd.

Ibatis works fantastic for getting data into classes.

You can use Ibatis to feed data and automatically create classes, then use JAXB to marshal the classes into an XML file! Mind you, that's a lot of effort if you're not going to be doing it over and over again.

Kieveli
+5  A: 

Look at pyXSD for Python tools that are similar to JAXB.

XSD's are used to create Python classes. Python objects are used to emit XML.

S.Lott
+1  A: 

I recommend two approaches:

  1. Xstream - it let's you generate XML files by defining a Java file and either putting Java annotations on the items or just defining aliases. It is very easy, but it is not fully automatic;

  2. XMLBeans - these tools let's you generate Java files from XML schema definitions (xsd) so that you can import, manipulate, create and export XML files using JavaBeans-like method calls.

Regards, Luis

Luis Soeiro
+2  A: 

Microsoft has published a "document generator" tool as a sample. This is an article that describes the architecture and operation of the sample app in some detail.

If you just want to use the document generation tool, click here and install the MSI. It requires no programming.

It's free. The source is available. Requires the .NET Framework to run. Works only with XSDs. (not Relax NG or DTD).

Cheeso
A: 

I use Exchanger XML Editor for this purpose. You can download it for free for multiple operating systems at: http://www.exchangerxml.com/

The option is in menu "Schema" -> "Schema instance generation".

Symen Timmermans