Connecting Tech Pros Worldwide Help | Site Map

XML datetime

Jason Huang
Guest
 
Posts: n/a
#1: May 1 '07
Hi,

In my C# windows form application, I can write a dataset to an XML file.
But everything in that XML are String type.
Is is possible to write a dataset to an XML file, so that the DateTime and
Int is still DateTime and Int in the XML?
Thanks for help.



Jason


Peter Duniho
Guest
 
Posts: n/a
#2: May 1 '07

re: XML datetime


On Mon, 30 Apr 2007 23:28:29 -0700, Jason Huang
<JasonHuang8888@hotmail.comwrote:
Quote:
In my C# windows form application, I can write a dataset to an XML file.
But everything in that XML are String type.
Is is possible to write a dataset to an XML file, so that the DateTime
and Int is still DateTime and Int in the XML?
Sure. Just format the data into a string, using an appropriate format for
the information you want to save. For an int, this would probably be the
default ToString() behavior, unless you had some reason to make it look
different in the XML file. For a DateTime, you would use a format that
preserves the portions of the DateTime that are important to you.

When reading the XML back in, just use the Parse() methods to recover the
original data from the strings.

Finally, keep in mind that I've never used the built-in .NET XML handling
classes. Given that the project Settings property handles this sort of
thing for you, it's possible that the built-in .NET XML stuff has a way to
do this automatically rather than making you Format and Parse yourself.
Maybe someone else will point out a better way than the above.

Pete
Jason Huang
Guest
 
Posts: n/a
#3: May 2 '07

re: XML datetime


Thanks Peter.
I output the DateTime field to the format of 'YYYY/MM/DD', then it works
fine.

"Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com¼¶¼g©ó¶l¥ó·s»D:op.trm 1d1nq8jd0ej@petes-computer.local...
Quote:
On Mon, 30 Apr 2007 23:28:29 -0700, Jason Huang
<JasonHuang8888@hotmail.comwrote:
>
Quote:
>In my C# windows form application, I can write a dataset to an XML file.
>But everything in that XML are String type.
>Is is possible to write a dataset to an XML file, so that the DateTime
>and Int is still DateTime and Int in the XML?
>
Sure. Just format the data into a string, using an appropriate format for
the information you want to save. For an int, this would probably be the
default ToString() behavior, unless you had some reason to make it look
different in the XML file. For a DateTime, you would use a format that
preserves the portions of the DateTime that are important to you.
>
When reading the XML back in, just use the Parse() methods to recover the
original data from the strings.
>
Finally, keep in mind that I've never used the built-in .NET XML handling
classes. Given that the project Settings property handles this sort of
thing for you, it's possible that the built-in .NET XML stuff has a way to
do this automatically rather than making you Format and Parse yourself.
Maybe someone else will point out a better way than the above.
>
Pete

Closed Thread