Class for deserializing array
-
This is probably a "Doh!" moment... I had stored some values in an XML file thus: f1 f2 f3 f4 f1 f2 f3 f4 I wanted to deserialize these into into a class so I could enumerate each command, and then the string array of fields. Long story short is I got lost in the Xml.Serialization namespace attributes, and gave up. The root was easy, an [XmlRoot("Commands")] public class Commands which contained a Command array. However I could not figure out how to get the Command array to return an array of Field[] strings. Anything like public string Field[] would result in value In the end I gave up and rewrote the XML by adding an intermediate class Fields which I could prefix with [XmlArray("Fields"), XmlArrayItem("Field")].. f1 f2 f3 f4 f1 f2 f3 f4 But is there a way to achieve the original result?? 'Howard
-
This is probably a "Doh!" moment... I had stored some values in an XML file thus: f1 f2 f3 f4 f1 f2 f3 f4 I wanted to deserialize these into into a class so I could enumerate each command, and then the string array of fields. Long story short is I got lost in the Xml.Serialization namespace attributes, and gave up. The root was easy, an [XmlRoot("Commands")] public class Commands which contained a Command array. However I could not figure out how to get the Command array to return an array of Field[] strings. Anything like public string Field[] would result in value In the end I gave up and rewrote the XML by adding an intermediate class Fields which I could prefix with [XmlArray("Fields"), XmlArrayItem("Field")].. f1 f2 f3 f4 f1 f2 f3 f4 But is there a way to achieve the original result?? 'Howard
There is no direct way to achieve the original: f1 f2 f3 f4 f1 f2 f3 f4 since each would be considered a stand-alone class field with the same name (which would be a syntax error). However, you can use XSLT to translate the deserialized format into the original format. "We make a living by what we get, we make a life by what we give." --Winston Churchill
-
There is no direct way to achieve the original: f1 f2 f3 f4 f1 f2 f3 f4 since each would be considered a stand-alone class field with the same name (which would be a syntax error). However, you can use XSLT to translate the deserialized format into the original format. "We make a living by what we get, we make a life by what we give." --Winston Churchill
Thanks - I sort of figured out that I must be doing it wrong as there did not seem to be a way to achieve it. So I wasn't missing something after all.
'Howard