XML Type Support Implementation Notes
This topic describes some implementation details that you want to be aware of.
List Mappings
The IList, ICollection, IEnumerable, Type[], and String types are used to represent XML Schema definition language (XSD) list types.
Union Mappings
Union types are represented using the XmlAtomicValue or String type. The source type or the destination type must therefore always be either String or XmlAtomicValue.
If the XmlSchemaDatatype object represents a list type the object converts the input string value to a list of one or more objects. If the XmlSchemaDatatype represents a union type then an attempt is made to parse the input value as a member type of the union. If the parse attempt fails then the conversion is attempted with the next member of the union and so on until the conversion is successful, or there are no other member types to try, in which case an exception is thrown.
Differences Between CLR and XML Data Types
The following describes certain mismatches that can occur between CLR types and XML data types and how they are handled.
Note
The xs
prefix is mapped to the https://www.w3.org/2001/XMLSchema and namespace URI.
System.TimeSpan and xs:duration
The xs:duration
type is partially ordered in that there are certain duration values that are different but equivalent. This means that for the xs:duration
type value such as 1 month (P1M) is less than 32 days (P32D), larger than 27 days (P27D) and equivalent to 28, 29 or 30 days.
The TimeSpan class does not support this partial ordering. Instead, it picks a specific number of days for 1 year and 1 month; 365 days and 30 days respectively.
For more information on the xs:duration
type, see the W3C XML Schema Part 2: Datatypes Recommendation.
xs:time, Gregorian Date Types, and System.DateTime
When an xs:time
value is mapped to a DateTime object, the MinValue field is used to initialize the date properties of the DateTime object (such as Year, Month, and Day) to the smallest possible DateTime value.
Similarly, instances of xs:gMonth
, xs:gDay
, xs:gYear
, xs:gYearMonth
and xs:gMonthDay
are also mapped to a DateTime object. Unused properties on the DateTime object are initialized to those from MinValue.
Note
You cannot rely on the DateTime.Year value when the content is typed as xs:gMonthDay
. The DateTime.Year value is always set to 1904 in this case.
xs:anyURI and System.Uri
When an instance of xs:anyURI
that represents a relative URI is mapped to a Uri, the Uri object does not have a base URI.