rcoast
asked on
Using DTD to open XML document with correct schema (C#, ADO.NET)
I need an example of an XML and DTD, so I can learn how to open a DataSet object, while preserving the data types, sizes, and other schema from the data. I am using C#.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for this... but I'm not sure if this is what I need.
I'm going to get an XML file from an external source, with a schema (I wrote DTD, but I assume XSD is the best way to do this).
I want to load the XML, using the XSD (or DTD) into a dataset that is strongly typed, at runtime, not design time.
The goal is that I want my dataset to know which fields are integers, which are floats, which are allowed nulls, etc...
But, my problem is, I will not have the luxury of running a command line tool to generate C# (or VB) code at runtime.
I'm going to get an XML file from an external source, with a schema (I wrote DTD, but I assume XSD is the best way to do this).
I want to load the XML, using the XSD (or DTD) into a dataset that is strongly typed, at runtime, not design time.
The goal is that I want my dataset to know which fields are integers, which are floats, which are allowed nulls, etc...
But, my problem is, I will not have the luxury of running a command line tool to generate C# (or VB) code at runtime.
ASKER
This is the one. Thanks!
Xsd file (schema) will tell the dataset all datatypes etc. That is what schema for.
So, at run time you create a dataset, read schema - now dataset knows about types etc.
Than you load data from xml.
In this scenario the hardest part is to create xsd. If you are not proficient - this might be a tricky task.
What I do sometimes: I create a dataset, create tables for dataset, define types for columns etc. All from code. Then I call dataset.WriteXmlSchema - and I have a schema file I can reuse for my application.
So, at run time you create a dataset, read schema - now dataset knows about types etc.
Than you load data from xml.
In this scenario the hardest part is to create xsd. If you are not proficient - this might be a tricky task.
What I do sometimes: I create a dataset, create tables for dataset, define types for columns etc. All from code. Then I call dataset.WriteXmlSchema - and I have a schema file I can reuse for my application.
If you have xml and schema - that's all you need to load proper types to a dataset etc.
See for example http://www.developer.com/db/article.php/3069061