Convert XSD into SQL relational tables - c#

Is there something available that could help me convert a XSD into SQL relational tables? The XSD is rather big (in my world anyway) and I could save time and boring typing if something pushed me ahead rather than starting from scratch.
The XSD is here if you want to have a look. It's a standardized/localized format to exchange MSDS.

Altova's XML Spy has a feature that will generate SQL DDL Script from an XSD file. XML Spy will cost you some money though.
Interestingly enough, a developer used a really clever trick of using an XSLT translation to create the DDL script from an XSD file. They have outlined it in two parts here and here.
I might have to try this out myself for future use...
EDIT: Just found this question asked previously here...

There is a command-line tool called XSD2DB, that generates database from xsd-files, available at sourceforge.
For more info: please refer to this existing question How can I create database tables from XSD files?

You can use an XSLT transform. See, for example, here: Generating SQL from XSD and XSL stylesheets with XSLT.
Microsoft has a command-line tool for performing XSLT transformations: Microsoft Command-Line tool for XSLT.
It is also easy to integrate the transforms into a build process using MSBuild or Grunt.
Here is the reference for the Microsoft documentation: XML Standards Reference, including XSD, XSLT, etc.

Related

Generate class from XSD - compact solution

I have XSD file, which seems rather complex (I am very new to working with XSD).
My task is to create a program, which would generate XML files based on the XSD schema (in a more detail - we will get a CSV file with the data and these need to be serialized into a XML). I did a research and tried various techniques of generating C# class from the XSD file, where the most 'compact' was xsd2code plugin for Visual Studio.
Nonetheless, this plugin has generated over 7,000 lines of code which quite shocked me as it was just one giant mess (for me).
My question now is - is there a better way (or maybe some switch I forgot to check) which will generate rather compact C# class? If not, then what is the next step that people have to do once they get C# class? Do they have to additional manual post processing so that the file is more 'programmer-friendly', or ...?
Thank you for your guidance; any help or tip will be highly appreciated!

Get all mandatory fields in a xsd schema file

Working against an xsd and I need to give a list of all mandatory fields to a client
Is there a way i can quickly do in c#? or use a free tool?
File is quite big I would like to avoid to do it manually
thanks
you could try xsd2code which is a codeplex project. See here This makes classes within your code based on the Xsd format.
This is a free tool integrated into your visual studio and might help you find the necessary fields. As well that it allows you to create code easily to the xsd schema.

Python XML Parse (using schema to generate dataset)

I'm looking to parse a xml file using Python and I was wondering if there was any way of automating the task over manually walking through all xml nodes/attributes using xml.dom.minidom library.
Essentially what would be sweet is if I could load a xml schema for the xml file I am reading then have that automatically generate some kind of data struct/set with all of the data within the xml.
In C# land this is possible via creating a strongly typed dataset class from a xml schema and then using this dataset to read the xml file in.
Is there any equivalent in Python?
lxml is a super-robust xml parsing package. It includes a subpackage, lxml.objectify, that will make an object tree from your xml.
It doesn't generate a class from the schema -- that's probably more a C#/Java thing -- but it does do schema validation so you know what kind of object you're getting back (see "asserting a schema").
You might take a look at lxml.objectify, particularly the E-factory. It's not really an equivalent to the ADO tools, but you may find it useful nonetheless.
hey dude - take beautifulSoup - it is a super library. HEAD over to the site scraperwiki.com
the can help you!

There is any tool that creates a class from a XML for deserialization?

I have this XML file, and I want to deserialize it to an object. But I don't want to type its class definition. There is any tool that can create the C# code of the class for me, inferring the data types from sample data?
Yes. Out of the box, you can use xsd.exe to generate XSD files from XML. You can also use this tool to generate classes from XSD files.
The code it produces is limited, which is why there are some third party tools that have stepped in.
Two of those tools include LiquidXML (costs money) and CodeXS (free). We use CodeXS, because it is free and extensible. We have extended it quite a bit.
EDIT:
CodeXS has an online tool. Just give it an XSD. It produces your classes for you.
They also have a command-line tool (source code) which is extensible and doesn't require you to send the XSD to their web service. We use it as a pre-build step.
Liquid Technologies has a good tool for this purpose (Data binding) http://www.liquid-technologies.com/. You'll really need to define a schema though instead of letting such a tool "infer" it from sample data.
One of the benefits of Liquid that we've found is that it can also generate code for Java, C++, C#, VBA etc. All very consistent.
Check out LINQ-to-XSD
It requires that you write a schema for your XML but then it's pretty good about a direct translation to objects.

Jaxb equivalent in C#

Using JAXB in Java it is easy to generate from a xml schema file a set of Java classes that xml conforming to that schema can be deserialized to.
Is there some C# equivalent of JAXB? I know that Linq can serialize and deserialize classes to/from xml files. But how can I generate C# classes from xml schema file and then use this classes with linq?
If you're using Visual Studio, try the XML Schema Definition Tool. It takes your schema definitions and produces C# classes -- or it can go the other way and produce schema definitions from classes. It also has a number of other XML-related transformations.
There is a better tool from Microsoft called XsdObjectGen, the XSD Object Code Generator. It is like xsd.exe, but better. Also free, it is not part of the .NET SDK, but is a separate download.
Also see the SO question: XSDObjectGen vs Xsd.exe
Look into using DataSet. It's a bit of a different concept from using "Java Beans". The entire XML document is treated hierarchical set of tables all in a single class. The good part is that theory of encapsulation for OOP is actually enforced. Wow, Microsoft got something right that Sun pooched.
Anyway. You can also look at typed DataSet's if you want make things more interesting. I've used this on major projects with great success.

Categories

Resources