serialization - C# - How to serialize and derialize DataSet correctly? -
i cannot deserialize serialized dataset correctly if has dates. result dates considered separate table instead of columns itself. seems not parsed correctly. how fix this?
here variables under inspection after serialization , deserialization. can see deserializeddataset.tables has 2 counts original 1 count. printed table names , shows second table date. moreover, can access date column in original data set unable access in deserialized version.
here serialized data of dataset.
<?xml version="1.0" standalone="yes"?> <newdataset> <producttransactionsummary> <id>74517</id> <branchid>9999</branchid> <date xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <year>2016</year> <month>11</month> <day>10</day> <hour>18</hour> <minute>25</minute> <second>40</second> <millisecond>0</millisecond> </date> </producttransactionsummary> <producttransactionsummary> <id>74518</id> <branchid>9999</branchid> <date xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <year>2016</year> <month>11</month> <day>10</day> <hour>18</hour> <minute>25</minute> <second>40</second> <millisecond>0</millisecond> </newdataset>
here deserialized dataset.
<?xml version="1.0" standalone="yes"?> <newdataset> <producttransactionsummary> <id>74517</id> <branchid>9999</branchid> <date> <year>2016</year> <month>11</month> <day>10</day> <hour>18</hour> <minute>25</minute> <second>40</second> <millisecond>0</millisecond> </date> </producttransactionsummary> <producttransactionsummary> <id>74518</id> <branchid>9999</branchid> <date> <year>2016</year> <month>11</month> <day>10</day> <hour>18</hour> <minute>25</minute> <second>40</second> <millisecond>0</millisecond> </date> </producttransactionsummary> </newdataset>
here current code:
public static class transport { public static memorystream serialize(dataset dataset) { var memorystream = new memorystream(); dataset.writexml(memorystream, xmlwritemode.ignoreschema); dataset.writexml("input.xml"); memorystream.flush(); memorystream.position = 0; return memorystream; } public static dataset deserialize(memorystream stream) { var dataset = new dataset(); dataset.readxml(stream); dataset.writexml("output.xml"); return dataset; } }
Comments
Post a Comment