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 generated a cs-classes with the xsd-tool from some xml scheme. The scheme
I am using classes that were generated from an XML schema using the xsd.exe
I have generated a set of classes using xsd.exe and created an XML document
OK, I generated C# classes from my huge XSD file. Now I have a
I have this Maven task to generate Java classes from an XSD file using
I have two classes generated by LINQ2SQL both from the same table so they
I have a T4 template that generates classes from an xml file. How can
I have a schema (xsd), and I want to create xml files that conform
I generated some C# classes from an XSD using the Visual Studio XSD utility
I want to generate java code from xsd using JAXB 2.1 XJC. I have

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.