System.Xml.XmlReader.ReadElementContentAsDateTime Method

Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a DateTime object.

Syntax

public virtual DateTime ReadElementContentAsDateTime (string localName, string namespaceURI)

Parameters

localName
The local name of the element.
namespaceURI
The namespace URI of the element.

Returns

The element contents as a DateTime object.

Remarks

This method reads the start tag, the contents of the element, and moves the reader past the end element tag. It expands entities and ignores processing instructions and comments. The element can only contain simple content. That is, it cannot have child elements.

If the content is typed xsd:dateTime, the reader returns an unboxed DateTime object. If the content is not typed xsd:dateTime, the reader attempts to convert it to a DateTime object according to the rules defined by the tp://go.microsoft.com/fwlink/?LinkId=4871 recommendation.

Note:

You cannot rely on the DateTime.Year value when the content is typed as xsd:gMonthDay. System.Xml.XmlReader always sets the DateTime.Year value to 1904 in this case.

For more information, see Reading Typed Data.

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0