Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:43:40+00:00 2026-05-16T17:43:40+00:00

I have generated classes from xsd and want to serialize the DateTime . My

  • 0

I have generated classes from xsd and want to serialize the DateTime. My class looks like

private System.DateTime timeGMT; 

 [System.Xml.Serialization.XmlElementAttribute(DataType="time")] 
 public System.DateTime TimeGMT { 
     get { 
         return this.timeGMT; 
     } 
     set { 
         this.timeGMT= value; 
     } 
 }

But when I assign any DateTime object It serializes in format as

<TimeGMT>12:00:00.0000000-04:00</TimeGMT>

But I want it to be serialized as

<TimeGMT>12:00:00</TimeGMT>

I had a look at this question :

Serializing DateTime to time without milliseconds and gmt

which is similar to my case. But my problem is I also want to validate the generated xml against xsd. So I cannot convert the return type to string. If I use String as return type then get an exception while generating XML:

time is an invalid value for XMLElementAttribute.DataType property.The property may be specified for only primitive types.

Is there any other way out there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:43:40+00:00Added an answer on May 16, 2026 at 5:43 pm

    I didn’t change the XML schema because it is used as standard. I removed

    [System.Xml.Serialization.XmlElementAttribute(DataType="time")]  
    

    from my class and used the solution suggested in

    Serializing DateTime to time without milliseconds and gmt

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a T4 template that generates classes from an xml file. How can
I have a set of XSDs from which I generate data access classes, stored
I have a post-compilation step that manipulates the Java bytecode of generated classes. I'd
I have an automatically generated XML file for the game that I run. It
I have a core file generated on a remote system that I don't have
I have a number of generated .sql files that I want to run in
I have a generated HTML page with flash content in it. I am trying
I have a generated txt file. This file has certain lines that are superfluous,
I have a PHP-generated page which is displaying some data about a set of
I have long tables generated by datagrid control that go beyond the page width.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.