By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

XMLDocument serilization date format

P: n/a
RJA
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...b;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.

-RJA
Apr 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>Modify the serilization method to override the default datetime format?
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.
Modify the class datatype from DateTime?

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

Apr 11 '06 #2

P: n/a


RJA wrote:

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

Correct date format is
date1="2006-01-01T00:00:00"
That is not an XSD date, rather a dateTime.
My return XML date format is
date1="2006-01-01T00:00:00.0000000-05:00"


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

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 11 '06 #3

P: n/a
> Loop through the XMLDocument and update the date formatting before returning
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

Apr 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.