Click here to Skip to main content
15,899,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to bring an older .net (2003) program forward to VS 2010. It also looks like I may be stuck (if that's the word) with WPF as some of the tools I want to use were designed for that and not Windows forms. The old program read an xml file into a strongly typed dataset, and I would like to do that again. I can bring the xml in, create a schema for it, but at that point I'm stuck. There use to be an item under the Schema menu that created a strongly typed data set from a xsd file. That is gone and I can't seem to find how to do this. All help appreciated
Posted

1 solution

You cannot create data out of XML Schema Definition, because it represent not data, but meta-data. It is related to XML data in the same was as database schema is related to the database data. If you really want data representing meda-data, you need to parse Schema Definition in some program structure representing metadata; it can be done in different ways, depending on your decisions.

[EDIT]

Please see comments to this answer. All you need is this class: https://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschema%28v=vs.110%29.aspx[^].

You need to instantiate this class and, with its instance, read some instance of XML Schema:
https://msdn.microsoft.com/en-us/library/ms162681(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/5y5eyz59(v=vs.110).aspx[^].

Then you can traverse that schema and generate some code, mapping schema properties to some .NET data type the way you find convenient for you. In certain cases, it may even make sense to generate whole assemblies on the fly, using System.Reflection.Emit:
https://msdn.microsoft.com/en-us/library/system.reflection.emit%28v=vs.110%29.aspx[^].

(That last option would mean really difficult work which is hard to debug, good knowledge of IL and CIL, CLR model and other fundamentals.)

—SA
 
Share this answer
 
v4
Comments
[no name] 8-Mar-15 16:48pm    
I think he's talking about generating the strongly typed dataset-definition from the XSD.
Sergey Alexandrovich Kryukov 8-Mar-15 17:00pm    
Maybe you are right. The term "dataset" is somewhat ambiguous. If you mean creation of some types (classes and structures) representing dataset, this is quite possible. I do something similar, as it makes a lot of sense.
Please see my update to the answer, after [EDIT].

I must note that, foreseeing nearest future, one could expect the further discussion leading too far, trying to understand "what to do with all that?", and so on. This is is something which could be called a whole "metadata-driven technology" I personally developed since 2000 and later continues some different aspects of it in different companies. One basic idea is that all those data classes are well too similar, so it could be prudent not to code them, but model based on some more general common schema, meta2-data schema, which is composed of other meta2 entities representing data "class", "instance", "relationship", "description" and so on...

Thank you very much for this note.
—SA
[no name] 8-Mar-15 17:24pm    
You're welcome.
Regarding your second paragraph - you will probably have some kind of déjà vu when reading what I'm about to send you. I'm curious what you will say to that ;-)
- Sebastian
Sergey Alexandrovich Kryukov 8-Mar-15 17:38pm    
About déjà vu... there is a funny thing:
Please see my article Wish You Were Here... Only Once, it's epigraph, and not only... :-)
—SA
[no name] 8-Mar-15 18:09pm    
Hehe :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900