Connecting Tech Pros Worldwide Help | Site Map

Writing a date and time into an xml attribute with the DateTime datatype

  #1  
Old August 26th, 2008, 03:05 AM
Andy B
Guest
 
Posts: n/a
How do you write date and times into an attribute with a datetime databype?
I tried:
<NewsArticle Date="2008-05-11 11:20:00 AM">

But the schema generated from the xml file says the Date attribute is a
string. Then I tried:

<NewsArticle Date = 2008-05-11 11:20:00 Pm>

Again, this didn't work because the conversion program complained and told
me there was a parser error because there weren't quotes or apostrophes
around the date string. How do I fix this?



  #2  
Old August 26th, 2008, 11:45 AM
Martin Honnen
Guest
 
Posts: n/a

re: Writing a date and time into an xml attribute with the DateTime datatype


Andy B wrote:
Quote:
How do you write date and times into an attribute with a datetime databype?
I tried:
<NewsArticle Date="2008-05-11 11:20:00 AM">
Use the methods the XML APIs provide e.g.
writer.WriteStartElement("NewsArticle");
writer.WriteStartAttribute("Date");
writer.WriteValue(DateTime.Now);
writer.WriteEndAttribute();
writer.WriteEndElement();
gives e.g.

<NewsArticle Date="2008-08-26T12:40:17.890625+02:00" />

Quote:
But the schema generated from the xml file says the Date attribute is a
string.
I am not sure however the inference will try to infer an xs:dateTime
value but you can try that yourself.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  #3  
Old August 26th, 2008, 12:15 PM
Andy B
Guest
 
Posts: n/a

re: Writing a date and time into an xml attribute with the DateTime datatype


Got it.

"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:e%23uK6h2BJHA.1628@TK2MSFTNGP03.phx.gbl...
Quote:
Andy B wrote:
Quote:
>How do you write date and times into an attribute with a datetime
>databype? I tried:
><NewsArticle Date="2008-05-11 11:20:00 AM">
>
Use the methods the XML APIs provide e.g.
writer.WriteStartElement("NewsArticle");
writer.WriteStartAttribute("Date");
writer.WriteValue(DateTime.Now);
writer.WriteEndAttribute();
writer.WriteEndElement();
gives e.g.
>
<NewsArticle Date="2008-08-26T12:40:17.890625+02:00" />
>
>
Quote:
>But the schema generated from the xml file says the Date attribute is a
>string.
>
I am not sure however the inference will try to infer an xs:dateTime value
but you can try that yourself.
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM