<p>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?</p>

<p><strong>Edit</strong></p>

<p>There are apparently no free tools for this, and I agree that OxygenXML is one of the best tools for this.</p>

[{'answer_id': 17114, 'author': 'SCdF', 'author_id': 1666, 'author_profile': 'https://Stackoverflow.com/users/1666', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.altova.com/xmlspy.html" rel="nofollow noreferrer">XMLSpy</a> does that for you, although that\'s not free...</p>\n\n<p>I believe that <a href="https://www.liquid-technologies.com/xml-studio" rel="nofollow noreferrer">Liquid Xml Studio</a> does it for you and is free, but I have not personally used it to create test data.</p>\n'}, {'answer_id': 28121, 'author': 'levand', 'author_id': 3044, 'author_profile': 'https://Stackoverflow.com/users/3044', 'pm_score': 6, 'selected': True, 'text': '<p>I think Oxygen (<a href="http://www.oxygenxml.com/" rel="noreferrer">http://www.oxygenxml.com/</a>) 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.</p>\n\n<p>I do believe there is a free, fully-featured 30 day trial.</p>\n'}, {'answer_id': 41821, 'author': 'Sam Warwick', 'author_id': 3873, 'author_profile': 'https://Stackoverflow.com/users/3873', 'pm_score': 8, 'selected': False, 'text': '<p>In Visual Studio 2008 SP1 and later the <a href="http://msdn.microsoft.com/en-us/library/cc716766.aspx" rel="noreferrer">XML Schema Explorer</a> can create an XML document with some basic sample data:</p>\n\n<ol>\n<li>Open your XSD document</li>\n<li>Switch to XML Schema Explorer</li>\n<li>Right click the root node and choose "Generate Sample Xml"</li>\n</ol>\n\n<p><img src="https://i.stack.imgur.com/rKUY6.png" alt="Screenshot of the XML Schema Explorer"></p>\n'}, {'answer_id': 276886, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>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.</p>\n\n<p>The tutorial is available here:\n<a href="http://www.oasis-open.org/committees/download.php/29661/XSD%20and%20jCAM%20tutorial.pdf" rel="noreferrer">http://www.oasis-open.org/committees/download.php/29661/XSD%20and%20jCAM%20tutorial.pdf</a></p>\n\n<p>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 - <a href="http://www.jcam.org.uk" rel="noreferrer">http://www.jcam.org.uk</a> </p>\n\n<p>Enjoy, DW</p>\n'}, {'answer_id': 374256, 'author': 'falko', 'author_id': 47010, 'author_profile': 'https://Stackoverflow.com/users/47010', 'pm_score': 3, 'selected': False, 'text': '<p>You can use the XML Instance Generator which is part of the <a href="http://msv.java.net/" rel="noreferrer">Sun/Oracle Multi-Schema Validator</a>.</p>\n\n<p>It\'s README.txt states:</p>\n\n<blockquote>\n  <p>Sun XML Generator is a Java tool to generate various XML instances from\n  several kinds of schemas. It supports DTD, RELAX Namespace, RELAX Core,\n  TREX, and a subset of W3C XML Schema Part 1. [...]</p>\n  \n  <p>This is a command-line tool that can generate both valid and invalid\n  instances from schemas. It can be used for generating test cases for XML\n  applications that need to conform to a particular schema.</p>\n</blockquote>\n\n<p>Download and unpack <code>xmlgen.zip</code> from the <a href="http://java.net/downloads/msv/" rel="noreferrer">msv download page</a> and run the following command to get detailed usage instructions:</p>\n\n<blockquote>\n  <p><code>java -jar xmlgen.jar -help</code></p>\n</blockquote>\n\n<p>The tool appears to be released under a BSD license; the source code is accessible from <a href="http://java.net/projects/msv" rel="noreferrer">here</a></p>\n'}, {'answer_id': 730208, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Microsoft has published a "document generator" tool as a sample.  <a href="http://msdn.microsoft.com/en-us/library/aa302296.aspx" rel="noreferrer">This is an article</a> that describes the architecture and operation of the sample app in some detail. </p>\n\n<p>If you just want to run the sample generation tool, <a href="http://download.microsoft.com/download/0/A/2/0A2B9B6C-33B8-4B9D-BE0B-077F5CF46820/XmlSampleGenerator.msi" rel="noreferrer">click here</a> and install the MSI. </p>\n\n<p>It\'s free.  The source is available. Requires the .NET Framework to run.  Works only with XSDs. (not Relax NG or DTD).</p>\n'}, {'answer_id': 893214, 'author': 'Kieveli', 'author_id': 15852, 'author_profile': 'https://Stackoverflow.com/users/15852', 'pm_score': 2, 'selected': False, 'text': '<p>Microsoft Office has \'<a href="http://office.microsoft.com/en-us/infopath/default.aspx" rel="nofollow noreferrer">InfoPath</a>\', which takes an XSD as an import and lets you quickly and easily define a form-based editor for creating XML files.  It has two modes - one where you define the form, and another mode where you create the XML file by filling out the form.  I believe it first came with Office 2003, and most people never install it.  It shocks me at how much I like it.</p>\n'}, {'answer_id': 1142039, 'author': 'Florian Fankhauser', 'author_id': 104976, 'author_profile': 'https://Stackoverflow.com/users/104976', 'pm_score': 7, 'selected': False, 'text': '<p>In recent versions of the free and open source <a href="http://www.eclipse.org" rel="noreferrer">Eclipse</a> 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.\n<p>\nOf 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.</p>\n'}, {'answer_id': 2431451, 'author': 'Peter', 'author_id': 292211, 'author_profile': 'https://Stackoverflow.com/users/292211', 'pm_score': 1, 'selected': False, 'text': '<p>XMLBlueprint 7.5 can do the following:\n- generate sample xml from dtd\n- generate sample xml from relax ng schema\n- generate sample xml from xml schema</p>\n'}, {'answer_id': 3423417, 'author': 'Sprotty', 'author_id': 101719, 'author_profile': 'https://Stackoverflow.com/users/101719', 'pm_score': 1, 'selected': False, 'text': '<p>Liquid XML Studio has an <a href="https://www.liquid-technologies.com/xml-sample-builder" rel="nofollow noreferrer">XML Sample Generator</a> wizard which will build sample XML files from an XML Schema. The resulting data seems to comply with the schema (it just can\'t generate data for regex patterns). </p>\n\n<p><a href="https://www.liquid-technologies.com/xml-sample-builder" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OJDtO.png" alt="Generate an XML Sample from an XSD"></a></p>\n'}, {'answer_id': 4285157, 'author': 'otto.poellath', 'author_id': 11678, 'author_profile': 'https://Stackoverflow.com/users/11678', 'pm_score': 1, 'selected': False, 'text': '<p>The open source Version of <a href="http://www.soapui.org/" rel="nofollow">SoapUI</a> can generate SOAP requests from WSDL (which contains XSD type definitions), so it looks like there IS an open source implementation of this functionality. Unfortunately, I haven\'t figured out which library is used to to this.</p>\n'}, {'answer_id': 5114701, 'author': 'rolandpeng', 'author_id': 562680, 'author_profile': 'https://Stackoverflow.com/users/562680', 'pm_score': 3, 'selected': False, 'text': '<p>XML-XIG: XML Instance Generator</p>\n\n<p><a href="http://xml-xig.sourceforge.net/" rel="noreferrer">http://xml-xig.sourceforge.net/</a></p>\n\n<p>This opensource would be helpful.</p>\n'}, {'answer_id': 6209865, 'author': 'Michal Rames', 'author_id': 780439, 'author_profile': 'https://Stackoverflow.com/users/780439', 'pm_score': 3, 'selected': False, 'text': '<p>Seems like nobody was able to answer the question so far :)</p>\n\n<p>I use EclipseLink\'s MOXy to dynamically generate binding classes and then recursively go through the bound types. It is somewhat heavy, but it allows XPath value injection once the object tree is instantiated:</p>\n\n<pre><code>InputStream in = new FileInputStream(PATH_TO_XSD);\nDynamicJAXBContext jaxbContext = \n            DynamicJAXBContextFactory.createContextFromXSD(in, null, Thread.currentThread().getContextClassLoader(), null);\nDynamicType rootType = jaxbContext.getDynamicType(YOUR_ROOT_TYPE);\nDynamicEntity root = rootType.newDynamicEntity();\ntraverseProps(jaxbContext, root, rootType, 0);\n</code></pre>\n\n<p>TraverseProps is pretty simple recursive method:</p>\n\n<pre><code>private void traverseProps(DynamicJAXBContext c, DynamicEntity e, DynamicType t, int level) throws DynamicException, InstantiationException, IllegalAccessException{\n        if (t!=null) {\n            logger.info(indent(level) + "type [" + t.getName() + "] of class [" + t.getClassName() + "] has " + t.getNumberOfProperties() + " props");\n            for (String pName:t.getPropertiesNames()){\n                Class&lt;?&gt; clazz = t.getPropertyType(pName);\n                logger.info(indent(level) + "prop [" + pName + "] in type: " + clazz);\n                //logger.info("prop [" + pName + "] in entity: " + e.get(pName));\n\n                if (clazz==null){\n                    // need to create an instance of object\n                    String updatedClassName = pName.substring(0, 1).toUpperCase() + pName.substring(1);\n                    logger.info(indent(level) + "Creating new type instance for " + pName + " using following class name: " + updatedClassName );\n                    DynamicType child = c.getDynamicType("generated." + updatedClassName);\n                    DynamicEntity childEntity = child.newDynamicEntity();\n                    e.set(pName, childEntity);\n                    traverseProps(c, childEntity, child, level+1);\n                } else {\n                    // just set empty value\n                    e.set(pName, clazz.newInstance());\n                }\n            }\n        } else {\n            logger.warn("type is null");\n        }\n    }\n</code></pre>\n\n<p>Converting everything to XML is pretty easy:</p>\n\n<pre><code>Marshaller marshaller = jaxbContext.createMarshaller();\nmarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);\nmarshaller.marshal(root, System.out);\n</code></pre>\n'}, {'answer_id': 8557638, 'author': 'Aravind Yarram', 'author_id': 127320, 'author_profile': 'https://Stackoverflow.com/users/127320', 'pm_score': 0, 'selected': False, 'text': '<p>The <a href="http://www.k-int.com/products/OpenXSD" rel="nofollow">OpenXSD</a> library mentions that they have support for generating XML instances based on the XSD. Check that out.</p>\n'}, {'answer_id': 10600733, 'author': 'MarnixKlooster ReinstateMonica', 'author_id': 223837, 'author_profile': 'https://Stackoverflow.com/users/223837', 'pm_score': 0, 'selected': False, 'text': '<p>For completeness I\'ll add <a href="http://code.google.com/p/jlibs/wiki/XSInstance" rel="nofollow noreferrer">http://code.google.com/p/jlibs/wiki/XSInstance</a>, which was mentioned in a similar (but Java-specific) question: <a href="https://stackoverflow.com/q/4710852/223837">Any Java &quot;API&quot; to generate Sample XML from XSD?</a></p>\n'}, {'answer_id': 10914690, 'author': 'Pat B', 'author_id': 925792, 'author_profile': 'https://Stackoverflow.com/users/925792', 'pm_score': 3, 'selected': False, 'text': '<p>You can also use XMLPad (free to use) found here <a href="http://www.wmhelp.com" rel="noreferrer">http://www.wmhelp.com</a> \nto generate your xml samples.\nFrom the menu : XSD -> generate sample XML file.</p>\n'}, {'answer_id': 12086824, 'author': 'yamass', 'author_id': 524913, 'author_profile': 'https://Stackoverflow.com/users/524913', 'pm_score': 5, 'selected': False, 'text': '<p>For Intellij Idea users: </p>\n\n<p>Have a look at Tools -> XML Actions</p>\n\n<p><img src="https://i.stack.imgur.com/jUyW4.png" alt="enter image description here"></p>\n\n<p>Seems to work very well (as far as I have tested).</p>\n\n<p>Edit: </p>\n\n<p>As mentioned by @naXa, you can now also right-click on the XSD file and click  "Generate XML Document from XSD Schema..."</p>\n'}, {'answer_id': 12883675, 'author': 'Bambax', 'author_id': 64208, 'author_profile': 'https://Stackoverflow.com/users/64208', 'pm_score': 0, 'selected': False, 'text': '<p>XML Blueprint also does that; instructions here</p>\n\n<p><a href="http://www.xmlblueprint.com/help/html/topic_170.htm" rel="nofollow">http://www.xmlblueprint.com/help/html/topic_170.htm</a></p>\n\n<p>It\'s not free, but there\'s a 10-day free trial; it seems fast and efficient; unfortunately it\'s Windows only.</p>\n'}, {'answer_id': 50888442, 'author': 'Sphinxxx', 'author_id': 1869660, 'author_profile': 'https://Stackoverflow.com/users/1869660', 'pm_score': 0, 'selected': False, 'text': '<p>There\'s also <a href="http://xsd2xml.com/" rel="nofollow noreferrer">http://xsd2xml.com/</a>, an online XSD to XML generator</p>\n'}]
['https://Stackoverflow.com/questions/17106', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1428/']