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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:21:22+00:00 2026-06-18T15:21:22+00:00

I’m a but frustrated. I’m playing around with xml-files. So this is my automatically

  • 0

I’m a but frustrated. I’m playing around with xml-files. So this is my automatically created xml-File:

<Files>
<Lists>
    <oList>
      <Object>
        <Name>test1</Name>
        <DateCreated>2/11/2013 4:35:05 PM</DateCreated>
        <DateDeadline>2/17/2013 12:00:00 AM</DateDeadline>
        <Reward>none</Reward>
        <Description>chocolate amedei 9</Description>
      </Object>
    </oList>
  </Lists>
</Files>

The many start elements in the beginning have to be there because I want to extend the file later. So now I want to read this xml-file and create an object of a class (ThingsToDoObjects, it’s supposed to become a to-do-list some day) that needs exactly the parameters stored in the xml-file. This Object should be stored in a list. So this is what I have so far:

XmlDocument xmlListDoc = new XmlDocument();
            xmlListDoc.Load(xmlFilePath);
            foreach (XmlNode xnode in xmlListDoc.SelectNodes("Files/Lists/oList/Object"))
            {
                string n = xnode.SelectSingleNode("Name").InnerText.ToString();
                DateTime c = Convert.ToDateTime(xnode.SelectSingleNode("DateCreated").InnerText.ToString());
                DateTime d = Convert.ToDateTime(xnode.SelectSingleNode("DateDeadline").InnerText.ToString());

                string r = xnode.SelectSingleNode("Reward").InnerText.ToString();
                string de = xnode.SelectSingleNode("Description").InnerText.ToString();
                ThingsToDoObjects NeuObject = new ThingsToDoObjects(n, c, d, r, de);
                o.Add(NeuObject);
            }

Now when I debug the following happens:
n is created fine, c is created fine. But d just doesn’t work.It gives an error:

“The string was not recognized as a valid DateTime”

(That’s my translation from German, so maybe the error might be called a bit different. What’s going on there? I hope I just made some stupid mistake.

By the way: I tried the ParseExactly() method but it dind’t work either and gave the same error.

Thanks in advance to everone who answers.

  • 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-18T15:21:24+00:00Added an answer on June 18, 2026 at 3:21 pm

    (I’m assuming you can’t change the XML format itself. It would be much better to use a standard format, as suggested by dtb.)

    If you’ve got text in a known format, use DateTime.ParseExact or DateTime.TryParseExact. They will work, if you give them the right format. I usually use the invariant culture for parsing in these cases too – you don’t want a user culture’s date separators etc to mess things up. In this case, it looks like the format string you want is "M/d/yyyy h:mm:ss tt".

    Sample code:

    using System;
    using System.Globalization;
    
    class Test
    {
        static void Main()
        {
            string text = "2/17/2013 12:00:00 AM";
            string format = "M/d/yyyy h:mm:ss tt";
            DateTime value = DateTime.ParseExact(text, format,
                                                 CultureInfo.InvariantCulture,
                                                 DateTimeStyles.None);
            Console.WriteLine(value);
        }
    }
    

    I’d also strongly suggest using LINQ to XML if you can. It’ll make your XML handling a lot simpler than your current code.

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

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using an ASP request returning a XML file containing some latin characters. By
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and

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.