Generating XML files from SQL Server tables in C# using an XSD - c#

I'm trying to generate an XML file for a dataset across several SQL Server tables. I have an XSD definition for the desired dataset and was wondering if it's possible to use C#'s data objects to point to the tables, note their relationships, extract the data and populate an XML file going via the XSD validate. I'm fine with setting up the tables to EXACTLY represent the hierarchies in the final XML file if this helps.
Many thanks for any help.

You might try the following:
1) Create C# class files from the XSD using the xsd.exe tool.
2) Use an ORM to map the database objects to your C# classes.
3) Use the XmlSerializer class to convert C# objects to an XML document which will match your XSD.
See: http://msdn.microsoft.com/en-us/library/943242d1(v=vs.110).aspx

Related

Generate XML file from CSV using XSD

I am trying to implement a C# Windows Forms application to generate XML file from a CSV based on XML's schema. I want to do this as much generic as possible since I am going to transform more than 1000 csv/schemas. Any ideas would be appreciated.
There is a pretty good article exposing appropriate approach for this case
converting csv to xml with an xsd

Create SQL Server database tables from C# classes

Is it possible to automatically convert a lot of C# classes to SQL Server database tables ?
I need to import some xml files into SQL Server but using SSIS the runtime stops working as soon as I select the xsd file. However I easily converted the xsd to class files so that's why I am asking if its possible to have a workaround...
You can use Entity Framework Code First functionality, with a little extra work to get the tables done in your database.
There you have a good post on it by ScottGu
Yes, it's possible to automatically do this. Entity Framework has a model called Code First, which essentially does this: takes your C# classes and creates the database and tables automatically for you.
Take a look at this post by Scott Guthrie.
Other option you might test is DataSet.ReadXml() function. Drawback is the Dataset can't handle complexType="mixed", but it deals well with large files (my files had about 50M each). All tables and columns are named by XML tags and relations are autogenerated by DataSet itself.

Does Linq-to-Xml queries support intellisence in C#?

In my project I am using an XML-file for datastorage. I am accessing that file with linq-to-xml queries. Actually I have created that XML-file from my SQL-server database but as that tables in SQL contained more that 50 columns, the resulting XML-file is also having more than 50 elements...
Now while applying queries I initially load that XML-file in XDocument object and after that applying queries on that.
My main problem is that as it contain more than 50 element it is very difficult to write queries without intellisence support. Why it is not supporting intellisence? What have I done wrong? What can I do to get intellisence support?
LINQ to XML is based on strings and it isn't confined to documents that follow some schema. That's the reason you don't get IntelliSense, VS has no information about the schema.
If this is really important for you, maybe using something like xsd.exe to generate classes that represent the schema would be better for you.
It's not possible to get intellisense for Linq to Xml.
This is because you load a file at runtime and you expect it to have compile time intellisense. What if you would load a different file at runtime, would you then get a compile time error?
What you could do is generate classes from your Xml file and then deserialize your XML file into these classes. The you can use Linq To Objects to access the data.
Here is some documentation for creating your classes.

Convert a c# mdb solution to xml?

I have a system that uses an mdb database with an xsd descriptor written in c#. Now I want to use one or more xml files with the same data instead. I have generated a couple of adapters for the mdb, but now I don't know what is needed for using xml instead. Anyone have some tips? I have managed to save the mdb as a few xml files.
Very unclear, XML is a very poor substitute for a database. I reckon you'll want to use DataTable or DataSet to load the .mdb data. Their WriteXml() method makes it very easy to generate the xml.
The XML is not fully substitute for relation database. The dataadapters are not supposed to work with XML files and the SQL language too. I recommend you choose another SQL database (you need propably some embeded database - such as Firebird, PostreSQL, SQLite, MSSQL CE, etc...). You can still use a OLE DB data providers (DataAdapters, DataReaders, etc...) and the data layer will need only little change because of SQL dialects.
However, if you need the data in XML, you need change whole data access layer.

Working with Database using LINQ to XML

I am Working on a project (C#) in the university and they said that we can't use a DBMS like SQL Server so we decide to use Linq and XML...we learned some basics in Linq to Xml But really we don't know how we can create tables and fields and work with them in Xml.any suggestions ?
The simplest option would be a Typed Dataset saved to an XML file. (With or without LINQ)
You would use it just like an RDBMS, but it isn't an RDMS, so it should be allowed.
If it's a single user application you can just create a serializable class and use that to store your data. Then when your app is closed the data class is serialized (binarily) to a file, and when the app starts it reads the file and all your data is still there.
Here is a simple example from the docs.
If you really want to use tables, you can create a Typed DataSet and Save/Load it as (proprietary) XML.
A DataSet can hold multiple tables + relations between them.

Categories

Resources