all groups > dotnet xml > april 2006 >
You're in the

dotnet xml

group:

XMLDocument serilization date format


XMLDocument serilization date format RJA
4/7/2006 2:52:01 PM
dotnet xml:
Hiyas,

Using VS .net 2003.

Setting up a Webservice that accepts 3rd party vendor designed XML requests
and returns a filled XMLDocument with response data.
Vendor XSDs were serialize into class objects to be used in the program.

EX: Used xsd.exe to turn VendorA_Request.XSD into VendorA_Request.cs
EX: Used xsd.exe to turn VendorA_Response.XSD into VendorA_Response.cs
etc etc..

Program logic is like this:
Webservice accepts an XML request as a string.
Deserialize the string into its appropriate request class object.
Run the request class through business logic and produce result class.
Serialize the result class into response XML document object to be returned.
Webservice returns the XMLDocument.

Problem:
Vendor XML schema verification is failing because the return date format are
incorrect.

Correct date format is
date1="2006-01-01T00:00:00"
My return XML date format is
date1="2006-01-01T00:00:00.0000000-05:00"

Because the XMLDocument object being returned is generated by serializing a
class object, I'm not sure how to get the correct formatting.

After hours of googling:
http://support.microsoft.com/default.aspx?scid=kb;en-us;811767

But that solution is assuming modification of the date format upon output.
Since the XMLDocument is not being outputted but is returning to the caller,
the solution does not work.

How should I go about correcting the date formatting inside the XMLDocument?
Modify the class datatype from DateTime?
Modify the serilization method to override the default datetime format?
Loop through the XMLDocument and update the date formatting before returning
it?
Use XSLT to produce a new XMLDocument with the correct format?

Any help will be greatly appreciated.

Re: XMLDocument serilization date format dickster
4/11/2006 8:40:09 AM
[quoted text, click to view]
If this is possible i would like to see it - But I dont think so think

NB: You can relate The XSD type xsd:date, xsd:dateTime to the CLR type
System.DateTime

<XmlElement(DataType:="date", ElementName:="date1")> _
Public Property dt() As DateTime
...
or
<XmlElement(DataType:="dateTime", ElementName:="date1")> _
Public Property dt() As DateTime
...


but neither of these are in the format you want.

[quoted text, click to view]
to say String - yes a possible solution

==============================================
Private _dt As DateTime

<XmlElement(ElementName:="date1")> _
Public Property dt() As String
Get
Return _dt.ToString("yyyy-MM-ddThh:mm:ss")
End Get
Set(ByVal Value As String)
_dt = Value
End Set
End Property
==============================================


Dickster
Re: XMLDocument serilization date format dickster
4/11/2006 8:50:37 AM
[quoted text, click to view]
it?

You could update the .InnerXml property of each <date1> node but this
feels like a less than slick solution.

However not to rule it out - Perhaps you could write a method which you
apply to each of the relevant nodes

i.e using SelectSingleNode or SelectNodes on the XmlDocument assign the
value of original .InnerXml of each <date1> node to a DateTime Object
and use the .ToString("yyyy-MM-ddThh:mm:ss") to return the result and
reassign to .InnerXml

There's probably better formatting solution but I think this would do
the job.

Dickster
Re: XMLDocument serilization date format Martin Honnen
4/11/2006 5:42:10 PM


[quoted text, click to view]


[quoted text, click to view]

That is not an XSD date, rather a dateTime.

[quoted text, click to view]

That is a dateTime too, with some milliseconds and a time zone
information which is allowed.



--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button