Any tools to generate an XSD schema from an XML instance document?

XmlXsdSchemaGenerator

Xml Problem Overview


I am looking for a tool which will take an XML instance document and output a corresponding XSD schema.

I certainly recognize that the generated XSD schema will be limited when compared to creating a schema by hand (it probably won't handle optional or repeating elements, or data constraints), but it could at least serve as a quick starting point.

Xml Solutions


Solution 1 - Xml

the https://msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.110).aspx">Microsoft XSD inference tool is a good, free solution. Many XML editing tools, such as XmlSpy (mentioned by @Garth Gilmour) or OxygenXML Editor also have that feature. They're rather expensive, though. BizTalk Server also has an XSD inferring tool as well.

edit: I just discovered the .net http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemainference.aspx">XmlSchemaInference</a> class, so if you're using .net you should consider that

Solution 2 - Xml

You can use an open source and cross-platform option: inst2xsd from Apache's XMLBeans. I find it very useful and easy.

Just download, unzip and play (it requires Java).

Solution 3 - Xml

Trang is the best option here. Open source and cross platform (although Java is required)

From the Trang Website:

>Trang converts between different schema languages for XML. It supports the following languages > > * RELAX NG (XML syntax) > * RELAX NG compact syntax > * XML 1.0 DTDs > * W3C XML Schema > >A schema written in any of the supported schema languages can be converted into any of the other supported schema languages, except that W3C XML Schema is supported for output only, not for input. > > Trang can also infer a schema from one or more example XML documents.

Download Link

Solution 4 - Xml

In VS2010 if you load an XML file into the editor, click the XML menu >> Create Schema.

Solution 5 - Xml

There also is XML schema learner which is available on Github.

It can take multiple xml files and extract a common XSD from all of those files.

Solution 6 - Xml

If you have .Net installed, a tool to generate XSD schemas and classes is already included by default.
For me, the XSD tool is installed under the following structure. This may differ depending on your installation directory.

C:\Program Files\Microsoft Visual Studio 8\VC>xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.

xsd.exe -
   Utility to generate schema or class files from given source.

xsd.exe <schema>.xsd /classes|dataset [/e:] [/l:] [/n:] [/o:] [/s] [/uri:]
xsd.exe <assembly>.dll|.exe [/outputdir:] [/type: [...]]
xsd.exe <instance>.xml [/outputdir:]
xsd.exe <schema>.xdr [/outputdir:]

Normally the classes and schemas that this tool generates work rather well, especially if you're going to be consuming them in a .Net language

I typically take the XML document that I'm after, push it through the XSD tool with the /o:<your path> flag to generate a schema (xsd) and then push the xsd file back through the tool using the /classes /L:VB (or CS) /o:<your path> flags to get classes that I can import and use in my day to day .Net projects

Solution 7 - Xml

If all you want is XSD, LiquidXML has a free version that does XSDs, and its got a GUI to it so you can tweak the XSD if you like. Anyways nowadays I write my own XSDs by hand, but its all thanks to this app.

http://www.liquid-technologies.com/

Solution 8 - Xml

if you are working in the java world - intelliJ idea has also extensive xml support, including xsd generation and samle xml from xsd generation, and with plugins you can get xslt debuggers. - especially nice if you plan to use tools such as jaxb afterwards.

Solution 9 - Xml

Altova XmlSpy does this well - you can find an overview here

Solution 10 - Xml

This is an old thread but I thought it could be useful to post this link: just found this tool: xsd-gen Generate XML Schema from XML

and it just did what I needed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatt DillardView Question on Stackoverflow
Solution 1 - XmlDanimalView Answer on Stackoverflow
Solution 2 - XmlDarioView Answer on Stackoverflow
Solution 3 - XmlDerfermanView Answer on Stackoverflow
Solution 4 - XmlNathan DonnellanView Answer on Stackoverflow
Solution 5 - XmledorianView Answer on Stackoverflow
Solution 6 - XmlPat HermensView Answer on Stackoverflow
Solution 7 - XmlRobert GouldView Answer on Stackoverflow
Solution 8 - XmlAndreas PeterssonView Answer on Stackoverflow
Solution 9 - XmlGarth GilmourView Answer on Stackoverflow
Solution 10 - Xmlv_eView Answer on Stackoverflow