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 7913425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:50:29+00:00 2026-06-03T13:50:29+00:00

I have one problem. I have to serialize an object and that sam object

  • 0

I have one problem. I have to serialize an object and that sam object is converted to XML, but it’s a datetime object.

Ok, i have string variable which is filled with data from some sql query, like this

//DateDeliveryRequest

 if (rw_mat["dat_pot"].ToString().Length <= 0)
     {
           date_req = "";
     }
     else
     {
           date_req = rw_mat["dat_pot"].ToString();
     }

Now, date_req is being passet to object like this:

var dtfi = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "-" };
Agr3PL.DataArea.Header.DateDeliveryRequest = Convert.ToDateTime(date_req, dtfi);

And at the end this object with among other is being passed to serialize function:

 private string SerializeAnObject(object obj)
            {

                System.Xml.XmlDocument doc = new XmlDocument();

                System.Xml.Serialization.XmlSerializer serializer = new        System.Xml.Serialization.XmlSerializer(obj.GetType());

                System.IO.MemoryStream stream = new System.IO.MemoryStream();

                try
                {

                    serializer.Serialize(stream, obj);

                    stream.Position = 0;

                    doc.Load(stream);

                    return doc.InnerXml;

                }

                catch (Exception ex)
                {
                    WriteErrors.WriteToLogFile("WS.SAVE_DOK_SERIJALIZACIJA", ex.ToString());

                    throw ex;

                }

So i want to get datetime variable to xml but I don’t, the xml has to look something like this(It is just a segment)

- <Header>
  <MessageType>COR</MessageType> 
  <UniqueHeaderNumber /> 
  <UniqueHeaderNumberFromWMS /> 
  <CompanyCode /> 
  <OrderNumber /> 
  <InvoiceNumber /> 
  <MovementNumber /> 
  <ReceiptNumber /> 
  <DebitNoteNumber /> 
  <PickNoteNumber /> 
  <LoadNumber /> 
  <DropSequence /> 
  <BulkPickNoteNumber /> 
  <NumberOfPallets />
  <DateDeliveryRequest />

But the problem is that the xml is not showing the node >DateDeliveryRequest it’s not there
I don’t get error just there is no node >DateDeliveryRequest???

I don’t know is it the problem in serializer function or on something else, maybe in formating date or something else?

  • 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-06-03T13:50:30+00:00Added an answer on June 3, 2026 at 1:50 pm

    I tested this code:

    public class Test
    {
        private DateTime dateDeliveryRequestField;
    
        [System.Xml.Serialization.XmlElementAttribute(DataType = "date")]
        public System.DateTime DateDeliveryRequest { get { return this.dateDeliveryRequestField; } set { this.dateDeliveryRequestField = value; } }
    }
    
    private string SerializeAnObject(object obj)
    {
        System.Xml.XmlDocument doc = new XmlDocument();
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        try
        {
           serializer.Serialize(stream, obj);
           stream.Position = 0;
           doc.Load(stream);
           return doc.InnerXml;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    
    Test n = new Test();
    n.DateDeliveryRequest = DateTime.Parse("2012-10-07");
    string result = SerializeAnObject(n);
    

    and result:

    <?xml version="1.0"?>
    <Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <DateDeliveryRequest>2012-10-07</DateDeliveryRequest>
    </Test>
    

    So everything looks good.

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

Sidebar

Related Questions

I'm almost finished with my program, but I have one problem that I can't
I have an object Foo which I serialize to an XML stream. public class
I have one problem , I want to get some data from XML file
i have one problem controlling checkbox, i'm reading, and searching about the topic but
I won't create wallpaper-application but have one problem. Please tell me how add ImageView
We have an existing application for which one of our DTO object has a
My goal is use the .NET DateTime object (in C#) and have that be
I need to serialize an object using datacontract serializer. The problem is that i
I have one problem, I learn how work with socket and I write programm
i have one problem when i sort the NSMutablearray using date and time wise.

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.