Parse Custom XML type into DataSet
-
Suppose I have a custom type made of a list of floats, and I want to represent it compactly in XML like this: [2.718, 3.142, 1.613, 1.000] Suppose also that I have a dataset, with a datatable where one of the columns uses MyType, which is a essentailly a float[]. My question is this: How do I ensure the tag is written into this format and read properly back into the float[] when I use ds.WriteXml and ds.ReadXml mehtods? Is there an interface or something I implement in my custom type to write on the contents for the tag and also to parse it back in? -- James --
-
Suppose I have a custom type made of a list of floats, and I want to represent it compactly in XML like this: [2.718, 3.142, 1.613, 1.000] Suppose also that I have a dataset, with a datatable where one of the columns uses MyType, which is a essentailly a float[]. My question is this: How do I ensure the tag is written into this format and read properly back into the float[] when I use ds.WriteXml and ds.ReadXml mehtods? Is there an interface or something I implement in my custom type to write on the contents for the tag and also to parse it back in? -- James --
Not without having to serialize the entire
DataSet
itself (using the undocumentedIXmlSerializable
interface) - not exactly something you want to do (it gets pretty complex if you want to remain compatible with the functionality of theDataSet
). You could try, however, to create a typedDataSet
(using xsd.exe or theDataSet
designer in VS.NET - right-click on your project or project folder, select Add->Add New Item and add a "DataSet"), then modify the hidden source code (use Project->Show All Files) to transform a string into afloat[]
. Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in yourDataSet
(well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from afloat[]
, from a logical perspective.Microsoft MVP, Visual C# My Articles
-
Not without having to serialize the entire
DataSet
itself (using the undocumentedIXmlSerializable
interface) - not exactly something you want to do (it gets pretty complex if you want to remain compatible with the functionality of theDataSet
). You could try, however, to create a typedDataSet
(using xsd.exe or theDataSet
designer in VS.NET - right-click on your project or project folder, select Add->Add New Item and add a "DataSet"), then modify the hidden source code (use Project->Show All Files) to transform a string into afloat[]
. Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in yourDataSet
(well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from afloat[]
, from a logical perspective.Microsoft MVP, Visual C# My Articles
Heath Stewart wrote: Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in your DataSet (well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from a float[], from a logical perspective. Your right. This is probably a better way to go. Thanks for your insight on this. -- James --