I'm having a bit of a mare with this.
Some of you may remember me whining on about reading in an xml file, which I sorted by Serializing it. Hooray.
Anyway, here's what I had:
An xml file
The xsd file for said xml file.
I used xsd.exe to generate classes from the xsd file, all good. But this had to (?) be done from the command line and if ever the layout or whatever of the xml changed, for example - if I later decide to add in some extra elements then I'd hate to regenerate the classes using xsd.exe, right?
That's not terrible, but is there a way to automate all that from within VS.net 2008?
I was told to check out MSDataSetGenerator as a custom tool, which is run against the .xsd file. It generates this huge wall of text (that crits you for 34,736) DataSet:
etc. etc. - However I haven't a clue what to do with it or how to use it.
The classes version as generated by xsd is much simpler and easier to understand, and just has properties for get/set each of the elements....piece o' cake to use. Even I understand it.
So essentially, what I'm doing at the moment is reading in this xml file that contains server config and e-mail recipients details, then accessing them via the generated class(es) like so:
And all is well. I can't post up any complete code, but I'd like to use the same .xml file with the dataset solution - if that's even possible. Like I said, I really don't understand datasets - well I would if it were connecting to a database, but it's not; it's just a flat xml file.
Does anyone have the slightest idea what i'm on about?
Some of you may remember me whining on about reading in an xml file, which I sorted by Serializing it. Hooray.
Anyway, here's what I had:
An xml file
The xsd file for said xml file.
I used xsd.exe to generate classes from the xsd file, all good. But this had to (?) be done from the command line and if ever the layout or whatever of the xml changed, for example - if I later decide to add in some extra elements then I'd hate to regenerate the classes using xsd.exe, right?
That's not terrible, but is there a way to automate all that from within VS.net 2008?
I was told to check out MSDataSetGenerator as a custom tool, which is run against the .xsd file. It generates this huge wall of text (that crits you for 34,736) DataSet:
Code:
private serverconfigDataTable tableserverconfig;
private recipientDataTable tablerecipient;
private triggersDataTable tabletriggers;
private global::System.Data.DataRelation relationrecipient_triggers;
private global::System.Data.SchemaSerializationMode _schemaSerializationMode = global::System.Data.SchemaSerializationMode.IncludeSchema;
etc. etc. - However I haven't a clue what to do with it or how to use it.
The classes version as generated by xsd is much simpler and easier to understand, and just has properties for get/set each of the elements....piece o' cake to use. Even I understand it.
So essentially, what I'm doing at the moment is reading in this xml file that contains server config and e-mail recipients details, then accessing them via the generated class(es) like so:
Code:
// Read in the XML file that contains list of e-mail recipients and associated triggers
TextReader reader = new StreamReader(ConfigurationFilename);
XmlSerializer serializer = new XmlSerializer(typeof(emailnotification));
emailnotification en = (emailnotification)serializer.Deserialize(reader);
// Get server connection details from xml config file
emailnotificationServerConfig sc = en.serverconfig
string server = sc.server;
string username = sc.username;
string password = sc.password;
And all is well. I can't post up any complete code, but I'd like to use the same .xml file with the dataset solution - if that's even possible. Like I said, I really don't understand datasets - well I would if it were connecting to a database, but it's not; it's just a flat xml file.
Does anyone have the slightest idea what i'm on about?