tool to generate xml file from xsd (for testing)

35,161

Solution 1

Eclipse has tools for doing this (and it's free.)

EDIT (yeah, I was a little too terse) : What you want are the XSD editing tools in Eclipse. I know it's bundled with Eclipse IDE for Java EE Developers, and I think also with the Eclipse Modeling Tools download. (It's also possible to add them into an existing Eclipse install, though I don't know exactly which plugin(s) you'll want to add.)

(I'd like to be more precise than that, but the eclipse.org web site models itself after Massachusetts roads: If you don't know where you are, you don't belong there.)

Anyway: Once you've got the right version of Eclipse, open the existing schema file for editing (or create a new one: select File -> New... Other ... XML / XML Schema ). When you're ready to generate a test XML file, locate the file in the Package Explorer (the navigator view, usually on the left side), right click on it, and select Generate/XML File.

(What was I saying about navigability... ?)

Solution 2

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 doc generation tool, click here and install the MSI.

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

Solution 3

Oxygen's XML Schema Editor can generate sample XML instance documents from a given Schema.

Solution 4

I can do this very simply in VS2010, I don't know if this has been a new feature but this works pretty easy. Right click on the root element of an xsd in the 'xml schema explorer'. You will see an option to 'Generate Sample XML'. On clicking it VS creates a temp file

Solution 5

Liquid XML will do XML sample generation, don't think there's a command line option but you can do it through the UI. Seems to do a pretty good job, gets all the data types/enums right, the only thing it seems to struggle on is patterns, but then understanding a regular expression well enough to produce a valid string is a bit tricky...

Share:
35,161
Tim
Author by

Tim

Busy

Updated on July 23, 2022

Comments

  • Tim
    Tim almost 2 years

    I have an xsd file and have not done much xml manipulation, parsing, etc. I want/need test xml files for my code but don't have any samples. (I am using xerces to parse)

    This is similar to: xml-instance-generation-from-xml-schema-xsd

    but I don't really want to make it a two step process. (python or java)

    I just want to feed xsd file to some tool and have it generate a sample xml file. How can I do that?

    Also see: how-to-generate-sample-xml-documents-from-their-dtd-or-xsd

  • Tim
    Tim about 15 years
    Can you elaborate? Is it in the basic/common install or is it a plugin? Link? Thanks
  • Tim
    Tim about 15 years
    this looks promising - I'll give the free trial a whirl.
  • Tim
    Tim about 15 years
    thanks. that helps. I'll try that as well.
  • Pops
    Pops about 14 years
    +1 for the Mass. roads; at least they're better than Pittsburgh roads (motto: if you can see it, you can't get there in a straight line). Tweak for MyEclipse users: in the context menu, select "MyEclipse > Generate XML File..."
  • pwaring
    pwaring almost 13 years
    Just to add that you must install the Web Tools Project for this to work, otherwise you won't have a Generate option on the menu. WTP might come installed by default on some distributions, but it definitely doesn't on Ubuntu, and I've just spent the best part of an hour figuring that out.
  • Mark Garcia
    Mark Garcia over 11 years
    Could you tell us a bit more of what you know about XMLFox? (A run-down of its features, caveats, etc.)