473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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?

Aug 26 '08 #1
2 3820
Andy B wrote:
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" />

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/
Aug 26 '08 #2
Got it.

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
Andy B wrote:
>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" />

>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/

Aug 26 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r =...
3
by: Dominic Messenger | last post by:
I have several elements that have optional child elements and attributes that are xs:dates. I have been using System.DateTime and the XmlAttribute/XmlElement attributes, but these will never work...
2
by: David Slinn | last post by:
I have created a simple XML document, generated a schema from it (which Visual Studio makes everything a string element). I then went through and changed all fields that are dates to the Date data...
12
by: Rob T | last post by:
I'm storing a date/time into a SQL table of type datetime. I need it to be precise so the value is stored to the 1000th of a second. ie "insert into myTable mydate values ('08/05/2005...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
3
by: Larry Bertolini | last post by:
For some reason, I recall having read that SQL Server 2005 would support a datatype that represented date, but not time. (This would be useful for storing things like birthday, where you usually...
10
by: Henrik Dahl | last post by:
Hello! I have an xml schema which has a date typed attribute. I have used xsd.exe to create a class library for XmlSerializer. The result of XmlSerializer.Serialize(...) should be passed as the...
16
by: Nathan Sokalski | last post by:
I have a control uses the date and time, including milliseconds. I want to be able to enter this information as an attribute in the *.aspx page. Because all attributes are entered as strings in the...
9
by: TC | last post by:
Hi. I have some ASP written in VB.net which is currently installed on a customers server. The asp connects to a local MySql database and retrieves data for the customers customers. If you see...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.