How to generate sample XML documents from their DTD or XSD?
Solution 1
I think Oxygen (http://www.oxygenxml.com/) does it as well, but that's another commerical product. It's a nice one, though... I'd strongly recommend it for anyone doing a lot of XML work. It comes in a nice Eclipse plugin, too.
I do believe there is a free, fully-featured 30 day trial.
Solution 2
In Visual Studio 2008 SP1 and later the XML Schema Explorer can create an XML document with some basic sample data:
- Open your XSD document
- Switch to XML Schema Explorer
- Right click the root node and choose "Generate Sample Xml"
Solution 3
In recent versions of the free and open source Eclipse IDE you can generate XML documents from DTD and XSD files. Right-click on a given *.dtd or *.xsd file and select "Generate -> XML File...". You can choose which root element to generate and whether optional attributes and elements should be generated.
Of course you can use Eclipse to create and edit your DTD and XSD schema files, too. And you don't need to install any plugins. It is included in the standard distribution.
Solution 4
For Intellij Idea users:
Have a look at Tools -> XML Actions
Seems to work very well (as far as I have tested).
Edit:
As mentioned by @naXa, you can now also right-click on the XSD file and click "Generate XML Document from XSD Schema..."
Solution 5
The camprocessor available on Sourceforge.net will do xml test case generation for any XSD. There is a tutorial available to show you how to generate your own test examples - including using content hints to ensure realistic examples, not just random junk ones.
The tutorial is available here: http://www.oasis-open.org/committees/download.php/29661/XSD%20and%20jCAM%20tutorial.pdf
And more information on the tool - which is using the OASIS Content Assembly Mechanism (CAM) standard to refactor your XSD into a more XSLT friendly structure - can be found from the resource website - http://www.jcam.org.uk
Enjoy, DW
Related videos on Youtube
lindelof
David's dayjob consists of working as a consultant for an IT company in Geneva. After dark he works on his main interests, which include home and building automation.
Updated on September 11, 2020Comments
-
lindelof over 3 years
We are developing an application that involves a substantial amount of XML transformations. We do not have any proper input test data per se, only DTD or XSD files. We'd like to generate our test data ourselves from these files. Is there an easy/free way to do that?
Edit
There are apparently no free tools for this, and I agree that OxygenXML is one of the best tools for this.
-
mjn almost 11 yearsI fail to see answers for this questions which do not fit the Q&A format, or solicit
debate, arguments, polling, or extended discussion
-
-
Admin over 15 yearsDirect link to Sourceforge.net download is: sourceforge.net/projects/camprocessor
-
Hans-Peter Störr over 15 yearsIt generates something, but you don't have much control over it: you can choose the toplevel element and some general options, but you cannot use XMLSpy to generate set of testcases with many variants etc.
-
lindelof over 15 yearsVery nice! A little bit limited though. I tried it on an XSD that imports other XSD and it failed. But on a DTD it works very well. Thanks!
-
balint almost 15 yearsyes, this is the easiest way. Open XSD, switch to XML Schema Explorer, select the root node, right click and choose "Generate Sample Xml".
-
Rachel over 14 yearsI have an bunch of XSDs which in turn inherits schema's from different XSD's and I need to generate an XML file for testing purpose from this XSD, am using oxygenXML to do this but when I try to do it, it is not working for me and it says please define root node but than it does not allow me to do so. So if anyone had worked with oxygenXML do suggest of what could be way around for this ?
-
Akku over 13 yearsThanks! Eclipse is free, and this was the perfect solution.
-
Sean Kearon about 13 yearsThe installer drops a bunch of C# code onto your machine. Just dump those into LinqPad and you have your free XML instance generator. Ta dah!
-
otto.poellath about 13 yearsDo you guys happen to know what Eclipse feature provides this functionality? My "Generate" submenu has "JAXB Classes" as the only item.
-
pwaring almost 13 yearsYou need to install the Web Tools Project (look under Help->Install New Software) to get these options.
-
Eric H over 12 yearsThanks leveland. This answered my question as well! If you would like to come answer my question: stackoverflow.com/questions/7041388/…, I would be more than happy to mark yours as the answer.
-
David Hergert over 12 yearsEclipse seems like a good option, but I could not get the generation to follow imported XSDs. For example, if I had an XSD describing 3 elements, and one of those was a complexType that was defined in a referenced/imported XSD, it would not generate for that element. Any ideas?
-
Jarekczek over 11 years
-
Jarekczek over 11 yearsNot very user friendly. Throws a lot of exceptions, can't make it working after getting unexplained
NullPointerException
. -
Simon about 11 yearsI used this with VS2008, but I can't find this in VS2010. Can anybody confirm that this still exists?
-
Martijn about 11 yearsSame as Simon: I can’t find this in VS2010 either. According to MSDN, it should still be there, but it just won't show up anywhere in the UI... :-(
-
Nikita about 11 yearsis there a way to specify # of elements to generate (for sequences)?
-
Miguel Sevilla about 11 years@Simon: you only get the "Generate Sample XML" when you right click one of the elements in the schema explorer. Elements are depicted graphically via the green left/right angle brackets: "<>". You are probably right clicking a type, and the generate message will only generate it for elements (which makes sense).
-
Adam Matan almost 11 years@DavidHergert A simple workaround would be generating a stub type.
-
Adam Matan almost 11 yearsFlorian - Thanks. This just saved me 4 hours of xmlbeans guess-compile-fix iterations.
-
Steve Chambers almost 11 yearsI prefer this to the higher rated Visual Studio method as it has more options. (Visual Studio generated me a very scant XML file with anything nillable set to nil, whereas Eclipse gave me the option to populate these elements.) One minor q - does the XSD file have to be plonked somewhere in the workspace? I was hoping to be able to do it via Open File... for any file on my computer or network without copying it into the workspace but couldn't find a way.
-
Christian Vielma almost 11 yearsI think Eclipse is the best!
-
FLX over 9 yearsI tested every solution of this thread and this worked the best
-
Envek over 9 yearsDoes not work for me in latest RubyMine (v. 7.0, Intellij Idea based) with XSD with many imports. I've got nothing but error message.
-
stefan almost 9 yearsXML Schema Explorer is not present in Visual Studio 2013 for Web neither. VS2013 Community does have it.
-
osullivj about 8 yearsNote that you do need VS 2008 SP1 for this to work. I was running on a vanilla VS 2008, and XML Schema Overview did not appear on my View menu. After applying SP1 I was able to open a .xsd and have the Schema view appear automatically.
-
Eliot about 8 yearsNot available in Visual Studio Code (as of early 2016), but there in Visual Studio 2015 Community on Windows.
-
The Red Pea about 8 yearsI get a stack overflow or "WMHelp XmlPad has stopped working" when I choose "Generate Sample Data"
-
The Red Pea about 8 years"Schema Compilation Error"?
-
The Red Pea about 8 yearsIn my case, needed to use the
--example
file to contain tokens that can be used to generate a new sample file. It takes a sample to make a sample! Not easy... -
Matt almost 8 yearsUnfortunately where there's an
xsd:choice
in the xsd it only picks one, so it's a pretty anaemic example. -
Matt almost 8 yearsXMLSpy looked good but generated xml that then failed to validate against the xsd that was used to generate it. Fail. It also barfed on a
postiveinteger
field - putting*ERROR*
in instead -
Ghoti about 7 years@Pyderman - that's your settings - look up how to change them.
-
Davos about 7 years@TimAbell , if it's
xsd:choice
then an example xml file can only contain one of that choice. msdn.microsoft.com/en-us/library/ms256109(v=vs.110).aspx -
Rok T. over 6 yearsVisual Studio Community 2017 still has this feature.
-
RedGrittyBrick over 6 yearsjava.net links are basically dead.
-
naXa stands with Ukraine over 6 yearsIn newer versions, right-click on XSD and select "Generate XML Document from XSD Schema..."
-
naXa stands with Ukraine over 6 yearscan you please post a usage example?
-
Czar over 5 yearsConstantly says "Root element name is invalid" and doesn't do anything, "Ok" button inactive.
-
Mikanikal over 5 years9 years later, this is still working great for XSDs.
-
MeanGreen over 5 years@RokT. it does, but it's not able to generate a valid XML for me. The generated file immediately has a warning. The value -99 is obviously not valid for a NonNegativeInteger...
-
ka3ak about 3 yearsIt didn't generate a valid XML from an XSD unfortunately. However the other tools failed at this task - Eclipse, Intellij IDEA and even XMLSpy. The best I've found so far is liquid-technologies.com/online-xsd-to-xml-converter But even this one fails to generate a valid XML if there are patterns in XSD.
-
ka3ak about 3 yearsI tried this and ran it as suggested:
xsd-instance.sh purchase-order.xsd {http://jlibs.org}PurchaseOrder
Got an error:Error: Unable to initialize main class jlibs.xml.xsd.XSInstance Caused by: java.lang.NoClassDefFoundError: org/apache/xerces/xs/XSObject
-
sshaw about 2 years
-
Simon Logic almost 2 years"Generate XML Document from XSD Schema..." does not create really full xml actually. At least for 2021.3