2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.XML / System.Xml / XQueryConvert.cs
1 //
2 // System.Xml.Query.XQueryConvert
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2004 Novell Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 #if NET_2_0
31
32 using System;
33 using System.Globalization;
34 using System.IO;
35 using System.Text;
36 using System.Xml;
37 using System.Xml.Schema;
38 using System.Xml.XPath;
39
40 namespace System.Xml
41 {
42         public class XQueryConvert
43         {
44                 private XQueryConvert ()
45                 {
46                 }
47
48                 public static bool ShouldCheckValueFacets (XmlSchemaType schemaTypeDest)
49                 {
50                         XmlSchemaObjectCollection facets = null;
51                         XmlSchemaSimpleType st = schemaTypeDest as XmlSchemaSimpleType;
52                         if (st != null) {
53                                 XmlSchemaSimpleTypeRestriction r = st.Content
54                                         as XmlSchemaSimpleTypeRestriction;
55                                 if (r != null)
56                                         facets = r.Facets;
57                         }
58                         else {
59                                 XmlSchemaComplexType ct =
60                                         schemaTypeDest as XmlSchemaComplexType;
61                                 XmlSchemaSimpleContent sc = ct.ContentModel
62                                         as XmlSchemaSimpleContent;
63                                 if (sc != null) {
64                                         XmlSchemaSimpleContentRestriction r =
65                                                 sc.Content as XmlSchemaSimpleContentRestriction;
66                                         if (r != null)
67                                                 facets = r.Facets;
68                                 }
69                         }
70                         return facets != null && facets.Count > 0;
71                 }
72
73                 public static XmlTypeCode GetFallbackType (XmlTypeCode type)
74                 {
75                         switch (type) {
76                         case XmlTypeCode.AnyAtomicType:
77                                 return XmlTypeCode.Item;
78                         case XmlTypeCode.UntypedAtomic:
79                                 return XmlTypeCode.String;
80                         case XmlTypeCode.Notation:
81                                 return XmlTypeCode.QName;
82                         case XmlTypeCode.NormalizedString:
83                         case XmlTypeCode.Token:
84                         case XmlTypeCode.Language:
85                         case XmlTypeCode.NmToken:
86                         case XmlTypeCode.Name:
87                         case XmlTypeCode.NCName:
88                         case XmlTypeCode.Id:
89                         case XmlTypeCode.Idref:
90                         case XmlTypeCode.Entity:
91                                 return XmlTypeCode.String;
92                         case XmlTypeCode.NonPositiveInteger:
93                                 return XmlTypeCode.Decimal;
94                         case XmlTypeCode.NegativeInteger:
95                                 return XmlTypeCode.NonPositiveInteger;
96                         case XmlTypeCode.Long:
97                                 return XmlTypeCode.Integer;
98                         case XmlTypeCode.Short:
99                                 return XmlTypeCode.Int;
100                         case XmlTypeCode.Byte:
101                                 return XmlTypeCode.Int;
102                         case XmlTypeCode.NonNegativeInteger:
103                                 return XmlTypeCode.Decimal;
104                         case XmlTypeCode.UnsignedLong:
105                                 return XmlTypeCode.NonNegativeInteger;
106                         case XmlTypeCode.UnsignedInt:
107                                 return XmlTypeCode.Integer;
108                         case XmlTypeCode.UnsignedShort:
109                                 return XmlTypeCode.Int;
110                         case XmlTypeCode.UnsignedByte:
111                                 return XmlTypeCode.UnsignedShort;
112                         case XmlTypeCode.PositiveInteger:
113                                 return XmlTypeCode.NonNegativeInteger;
114                         default:
115                                 return XmlTypeCode.None;
116                         }
117                 }
118
119                 [MonoTODO]
120                 // See XQuery & XPath 2.0 functions & operators section 17.
121                 public static bool CanConvert (XPathItem item, XmlSchemaType schemaTypeDest)
122                 {
123                         if (item == null)
124                                 throw new ArgumentNullException ("item");
125                         if (schemaTypeDest == null)
126                                 throw new ArgumentNullException ("schemaTypeDest");
127                         XmlTypeCode src = item.XmlType.TypeCode;
128                         XmlTypeCode dst = schemaTypeDest.TypeCode;
129
130                         // Notation cannot be converted from other than Notation
131                         if (src == XmlTypeCode.Notation && dst != XmlTypeCode.Notation)
132                                 return false;
133
134                         // untypedAtomic and string are convertable unless source type is QName.
135                         switch (dst) {
136                         case XmlTypeCode.UntypedAtomic:
137                         case XmlTypeCode.String:
138                                 return src != XmlTypeCode.QName;
139                         }
140
141                         switch (src) {
142                         case XmlTypeCode.None:
143                         case XmlTypeCode.Item:
144                         case XmlTypeCode.Node:
145                         case XmlTypeCode.Document:
146                         case XmlTypeCode.Element:
147                         case XmlTypeCode.Attribute:
148                         case XmlTypeCode.Namespace:
149                         case XmlTypeCode.ProcessingInstruction:
150                         case XmlTypeCode.Comment:
151                         case XmlTypeCode.Text:
152                                 throw new NotImplementedException (); // FIXME: check what happens
153
154                         case XmlTypeCode.AnyAtomicType:
155                                 throw new NotImplementedException (); // FIXME: check what happens
156                         case XmlTypeCode.UntypedAtomic:
157                         case XmlTypeCode.String:
158                                 // 'M'
159                                 throw new NotImplementedException (); // FIXME: check what happens
160
161                         case XmlTypeCode.Boolean:
162                         case XmlTypeCode.Decimal:
163                                 switch (dst) {
164                                 case XmlTypeCode.Float:
165                                 case XmlTypeCode.Double:
166                                 case XmlTypeCode.Decimal:
167                                 case XmlTypeCode.Boolean:
168                                         return true;
169                                 }
170                                 return false;
171
172                         case XmlTypeCode.Float:
173                         case XmlTypeCode.Double:
174                                 if (dst == XmlTypeCode.Decimal)
175                                         // 'M'
176                                         throw new NotImplementedException (); // FIXME: check what happens
177                                 goto case XmlTypeCode.Decimal;
178
179                         case XmlTypeCode.Duration:
180                                 switch (dst) {
181                                 case XmlTypeCode.Duration:
182                                 case XmlTypeCode.YearMonthDuration:
183                                 case XmlTypeCode.DayTimeDuration:
184                                         return true;
185                                 }
186                                 return false;
187
188                         case XmlTypeCode.DateTime:
189                                 switch (dst) {
190                                 case XmlTypeCode.DateTime:
191                                 case XmlTypeCode.Time:
192                                 case XmlTypeCode.Date:
193                                 case XmlTypeCode.GYearMonth:
194                                 case XmlTypeCode.GYear:
195                                 case XmlTypeCode.GMonthDay:
196                                 case XmlTypeCode.GDay:
197                                 case XmlTypeCode.GMonth:
198                                         return true;
199                                 }
200                                 return false;
201
202                         case XmlTypeCode.Time:
203                                 switch (dst) {
204                                 case XmlTypeCode.Time:
205                                 case XmlTypeCode.Date:
206                                         return true;
207                                 }
208                                 return false;
209
210                         case XmlTypeCode.Date:
211                                 if (dst == XmlTypeCode.Time)
212                                         return false;
213                                 goto case XmlTypeCode.DateTime;
214
215                         case XmlTypeCode.GYearMonth:
216                         case XmlTypeCode.GYear:
217                         case XmlTypeCode.GMonthDay:
218                         case XmlTypeCode.GDay:
219                         case XmlTypeCode.GMonth:
220                                 return src == dst;
221
222                         case XmlTypeCode.HexBinary:
223                         case XmlTypeCode.Base64Binary:
224                                 if (src == dst)
225                                         return true;
226                                 switch (dst) {
227                                 case XmlTypeCode.HexBinary:
228                                 case XmlTypeCode.Base64Binary:
229                                         return true;
230                                 }
231                                 return false;
232
233                         case XmlTypeCode.AnyUri:
234                         case XmlTypeCode.QName:
235                         case XmlTypeCode.Notation:
236                                 return src == dst;
237
238                         case XmlTypeCode.NormalizedString:
239                         case XmlTypeCode.Token:
240                         case XmlTypeCode.Language:
241                         case XmlTypeCode.NmToken:
242                         case XmlTypeCode.Name:
243                         case XmlTypeCode.NCName:
244                         case XmlTypeCode.Id:
245                         case XmlTypeCode.Idref:
246                         case XmlTypeCode.Entity:
247                         case XmlTypeCode.Integer:
248                         case XmlTypeCode.NonPositiveInteger:
249                         case XmlTypeCode.NegativeInteger:
250                         case XmlTypeCode.Long:
251                         case XmlTypeCode.Int:
252                         case XmlTypeCode.Short:
253                         case XmlTypeCode.Byte:
254                         case XmlTypeCode.NonNegativeInteger:
255                         case XmlTypeCode.UnsignedLong:
256                         case XmlTypeCode.UnsignedInt:
257                         case XmlTypeCode.UnsignedShort:
258                         case XmlTypeCode.UnsignedByte:
259                         case XmlTypeCode.PositiveInteger:
260                                 throw new NotImplementedException ();
261
262                         // xdt:*
263                         case XmlTypeCode.YearMonthDuration:
264                                 if (dst == XmlTypeCode.DayTimeDuration)
265                                         return false;
266                                 goto case XmlTypeCode.Duration;
267                         case XmlTypeCode.DayTimeDuration:
268                                 if (dst == XmlTypeCode.YearMonthDuration)
269                                         return false;
270                                 goto case XmlTypeCode.Duration;
271                         }
272
273                         throw new NotImplementedException ();
274                 }
275
276                 // Individual conversion
277
278                 public static string AnyUriToString (string value)
279                 {
280                         return value;
281                 }
282
283                 public static byte [] Base64BinaryToHexBinary (byte [] value)
284                 {
285                         return XmlConvert.FromBinHexString (Convert.ToBase64String (value));
286                 }
287
288                 public static string Base64BinaryToString (byte [] value)
289                 {
290                         return Convert.ToBase64String (value);
291                 }
292
293                 public static decimal BooleanToDecimal (bool value)
294                 {
295                         return Convert.ToDecimal (value);
296                 }
297
298                 public static double BooleanToDouble (bool value)
299                 {
300                         return Convert.ToDouble (value);
301                 }
302
303                 public static float BooleanToFloat (bool value)
304                 {
305                         return Convert.ToSingle (value);
306                 }
307
308                 public static int BooleanToInt (bool value)
309                 {
310                         return Convert.ToInt32 (value);
311                 }
312
313                 public static long BooleanToInteger (bool value)
314                 {
315                         return Convert.ToInt64 (value);
316                 }
317
318                 public static string BooleanToString (bool value)
319                 {
320                         // It looks not returning "True"
321                         return value ? "true" : "false";
322                 }
323
324                 public static DateTime DateTimeToDate (DateTime value)
325                 {
326                         return value.Date;
327                 }
328
329                 public static DateTime DateTimeToGDay (DateTime value)
330                 {
331                         return new DateTime (0, 0, value.Day);
332                 }
333
334                 public static DateTime DateTimeToGMonth (DateTime value)
335                 {
336                         return new DateTime (0, value.Month, 0);
337                 }
338
339                 public static DateTime DateTimeToGMonthDay (DateTime value)
340                 {
341                         return new DateTime (0, value.Month, value.Day);
342                 }
343
344                 public static DateTime DateTimeToGYear (DateTime value)
345                 {
346                         return new DateTime (value.Year, 0, 0);
347                 }
348
349                 public static DateTime DateTimeToGYearMonth (DateTime value)
350                 {
351                         return new DateTime (value.Year, value.Month, 0);
352                 }
353
354                 public static DateTime DateTimeToTime (DateTime value)
355                 {
356                         return new DateTime (value.TimeOfDay.Ticks);
357                 }
358
359                 public static DateTime DateToDateTime (DateTime value)
360                 {
361                         return value.Date;
362                 }
363
364                 public static DateTime DateToGDay (DateTime value)
365                 {
366                         return new DateTime (0, 0, value.Day);
367                 }
368
369                 public static DateTime DateToGMonth (DateTime value)
370                 {
371                         return new DateTime (0, value.Month, 0);
372                 }
373
374                 public static DateTime DateToGMonthDay (DateTime value)
375                 {
376                         return new DateTime (0, value.Month, value.Day);
377                 }
378
379                 public static DateTime DateToGYear (DateTime value)
380                 {
381                         return new DateTime (value.Year, 0, 0);
382                 }
383
384                 public static DateTime DateToGYearMonth (DateTime value)
385                 {
386                         return new DateTime (value.Year, value.Month, 0);
387                 }
388
389                 public static string DateToString (DateTime value)
390                 {
391                         return XmlConvert.ToString (value);
392                 }
393
394                 public static string DateTimeToString (DateTime value)
395                 {
396                         return XmlConvert.ToString (value);
397                 }
398
399                 public static string DayTimeDurationToDuration (TimeSpan value)
400                 {
401                         return XmlConvert.ToString (value);
402                 }
403
404                 public static string DayTimeDurationToString (TimeSpan value)
405                 {
406                         return DayTimeDurationToDuration (value);
407                 }
408
409                 public static bool DecimalToBoolean (decimal value)
410                 {
411                         return value != 0;
412                 }
413
414                 public static double DecimalToDouble (decimal value)
415                 {
416                         return Convert.ToDouble (value);
417                 }
418
419                 public static float DecimalToFloat (decimal value)
420                 {
421                         return Convert.ToSingle (value);
422                 }
423
424                 public static int DecimalToInt (decimal value)
425                 {
426                         return Convert.ToInt32 (value);
427                 }
428
429                 public static long DecimalToInteger (decimal value)
430                 {
431                         return Convert.ToInt64 (value);
432                 }
433
434                 [MonoTODO] // what if value was negative?
435                 public static decimal DecimalToNonNegativeInteger (decimal value)
436                 {
437                         // MS has a bug that does not reject negative values.
438                         throw new NotImplementedException ();
439                 }
440
441                 [MonoTODO] // what if value was positive?
442                 public static decimal DecimalToNonPositiveInteger (decimal value)
443                 {
444                         throw new NotImplementedException ();
445                 }
446
447                 public static string DecimalToString (decimal value)
448                 {
449                         return XmlConvert.ToString (value);
450                 }
451
452                 public static bool DoubleToBoolean (double value)
453                 {
454                         return value != 0;
455                 }
456
457                 public static decimal DoubleToDecimal (double value)
458                 {
459                         return (decimal) value;
460                 }
461
462                 public static float DoubleToFloat (double value)
463                 {
464                         return Convert.ToSingle (value);
465                 }
466
467                 public static int DoubleToInt (double value)
468                 {
469                         return Convert.ToInt32 (value);
470                 }
471
472                 public static long DoubleToInteger (double value)
473                 {
474                         return Convert.ToInt64 (value);
475                 }
476
477                 [MonoTODO] // what if value was negative?
478                 public static decimal DoubleToNonNegativeInteger (double value)
479                 {
480                         // MS has a bug that does not reject negative values.
481                         throw new NotImplementedException ();
482                 }
483
484                 [MonoTODO] // what if value was positive?
485                 public static decimal DoubleToNonPositiveInteger (double value)
486                 {
487                         throw new NotImplementedException ();
488                 }
489
490                 public static string DoubleToString (double value)
491                 {
492                         return XmlConvert.ToString (value);
493                 }
494
495                 public static TimeSpan DurationToDayTimeDuration (string value)
496                 {
497                         return XmlConvert.ToTimeSpan (value);
498                 }
499
500                 public static string DurationToString (string value)
501                 {
502                         return XmlConvert.ToString (XmlConvert.ToTimeSpan (value));
503                 }
504
505                 public static TimeSpan DurationToYearMonthDuration (string value)
506                 {
507                         return XmlConvert.ToTimeSpan (value);
508                 }
509
510
511                 public static bool FloatToBoolean (float value)
512                 {
513                         return value != 0;
514                 }
515
516                 public static decimal FloatToDecimal (float value)
517                 {
518                         return (decimal) value;
519                 }
520
521                 public static double FloatToDouble (float value)
522                 {
523                         return Convert.ToDouble (value);
524                 }
525
526                 public static int FloatToInt (float value)
527                 {
528                         return Convert.ToInt32 (value);
529                 }
530
531                 public static long FloatToInteger (float value)
532                 {
533                         return Convert.ToInt64 (value);
534                 }
535
536                 [MonoTODO] // what if value was negative?
537                 public static decimal FloatToNonNegativeInteger (float value)
538                 {
539                         // MS has a bug that does not reject negative values.
540                         throw new NotImplementedException ();
541                 }
542
543                 [MonoTODO] // what if value was positive?
544                 public static decimal FloatToNonPositiveInteger (float value)
545                 {
546                         throw new NotImplementedException ();
547                 }
548
549                 public static string FloatToString (float value)
550                 {
551                         return XmlConvert.ToString (value);
552                 }
553
554                 public static string GDayToString (DateTime value)
555                 {
556                         return XmlConvert.ToString (TimeSpan.FromDays (value.Day));
557                 }
558
559                 public static string GMonthDayToString (DateTime value)
560                 {
561                         return XmlConvert.ToString (new TimeSpan (value.Day, value.Hour, value.Minute, value.Second));
562                 }
563
564                 public static string GMonthToString (DateTime value)
565                 {
566                         return XmlConvert.ToString (new TimeSpan (0, value.Month, 0));
567                 }
568
569                 public static string GYearMonthToString (DateTime value)
570                 {
571                         return XmlConvert.ToString (new TimeSpan (value.Year, value.Month, 0));
572                 }
573
574                 public static string GYearToString (DateTime value)
575                 {
576                         return XmlConvert.ToString (new TimeSpan (new DateTime (value.Year, 0, 0).Ticks));
577                 }
578
579                 public static string HexBinaryToString (byte [] data)
580                 {
581                         return XmlConvert.ToBinHexString (data);
582                 }
583
584                 public static byte [] HexBinaryToBase64Binary (byte [] data)
585                 {
586                         return data;//XmlConvert.ToBinHexString (data);
587                 }
588
589
590                 public static bool IntegerToBoolean (long value)
591                 {
592                         return value != 0;
593                 }
594
595                 public static decimal IntegerToDecimal (long value)
596                 {
597                         return (decimal) value;
598                 }
599
600                 public static double IntegerToDouble (long value)
601                 {
602                         return Convert.ToDouble (value);
603                 }
604
605                 public static float IntegerToFloat (long value)
606                 {
607                         return Convert.ToSingle (value);
608                 }
609
610                 public static int IntegerToInt (long value)
611                 {
612                         return Convert.ToInt32 (value);
613                 }
614
615                 public static string IntegerToString (long value)
616                 {
617                         return XmlConvert.ToString (value);
618                 }
619
620                 public static bool IntToBoolean (int value)
621                 {
622                         return value != 0;
623                 }
624
625                 public static decimal IntToDecimal (int value)
626                 {
627                         return (decimal) value;
628                 }
629
630                 public static double IntToDouble (int value)
631                 {
632                         return Convert.ToDouble (value);
633                 }
634
635                 public static float IntToFloat (int value)
636                 {
637                         return Convert.ToSingle (value);
638                 }
639
640                 public static long IntToInteger (int value)
641                 {
642                         return value;
643                 }
644
645                 public static string IntToString (int value)
646                 {
647                         return XmlConvert.ToString (value);
648                 }
649
650                 public static string NonNegativeIntegerToString (decimal value)
651                 {
652                         return XmlConvert.ToString (value);
653                 }
654
655                 public static string NonPositiveIntegerToString (decimal value)
656                 {
657                         return XmlConvert.ToString (value);
658                 }
659
660                 public static DateTime TimeToDateTime (DateTime value)
661                 {
662                         return value;
663                 }
664
665                 public static string TimeToString (DateTime value)
666                 {
667                         return XmlConvert.ToString (value, "HH:mm:ssZ");
668                 }
669
670                 public static string YearMonthDurationToDuration (TimeSpan value)
671                 {
672                         return XmlConvert.ToString (value);
673                 }
674
675                 public static string YearMonthDurationToString (TimeSpan value)
676                 {
677                         return YearMonthDurationToDuration (value);
678                 }
679
680                 public static string StringToAnyUri (string value)
681                 {
682                         return value;
683                 }
684
685                 public static byte [] StringToBase64Binary (string value)
686                 {
687                         return Convert.FromBase64String (value);
688                 }
689
690                 public static bool StringToBoolean (string value)
691                 {
692                         return XmlConvert.ToBoolean (value);
693                 }
694
695                 public static DateTime StringToDate (string value)
696                 {
697                         return XmlConvert.ToDateTime (value);
698                 }
699
700                 public static DateTime StringToDateTime (string value)
701                 {
702                         return XmlConvert.ToDateTime (value);
703                 }
704
705                 public static TimeSpan StringToDayTimeDuration (string value)
706                 {
707                         return XmlConvert.ToTimeSpan (value);
708                 }
709
710                 public static decimal StringToDecimal (string value)
711                 {
712                         return XmlConvert.ToDecimal (value);
713                 }
714
715                 public static double StringToDouble (string value)
716                 {
717                         return XmlConvert.ToDouble (value);
718                 }
719
720                 public static string StringToDuration (string value)
721                 {
722                         return XmlConvert.ToString (XmlConvert.ToTimeSpan (value));
723                 }
724
725                 public static float StringToFloat (string value)
726                 {
727                         return XmlConvert.ToSingle (value);
728                 }
729
730                 public static DateTime StringToGDay (string value)
731                 {
732                         return XmlConvert.ToDateTime (value);
733                 }
734
735                 public static DateTime StringToGMonth (string value)
736                 {
737                         return XmlConvert.ToDateTime (value);
738                 }
739
740                 public static DateTime StringToGMonthDay (string value)
741                 {
742                         return XmlConvert.ToDateTime (value);
743                 }
744
745                 public static DateTime StringToGYear (string value)
746                 {
747                         return XmlConvert.ToDateTime (value);
748                 }
749
750                 public static DateTime StringToGYearMonth (string value)
751                 {
752                         return XmlConvert.ToDateTime (value);
753                 }
754
755                 public static byte [] StringToHexBinary (string value)
756                 {
757                         return XmlConvert.FromBinHexString (value);
758                 }
759
760                 public static int StringToInt (string value)
761                 {
762                         return XmlConvert.ToInt32 (value);
763                 }
764
765                 public static long StringToInteger (string value)
766                 {
767                         return XmlConvert.ToInt64 (value);
768                 }
769
770                 public static decimal StringToNonNegativeInteger (string value)
771                 {
772                         return XmlConvert.ToDecimal (value);
773                 }
774
775                 public static decimal StringToNonPositiveInteger (string value)
776                 {
777                         return XmlConvert.ToDecimal (value);
778                 }
779
780                 public static DateTime StringToTime (string value)
781                 {
782                         return XmlConvert.ToDateTime (value);
783                 }
784
785                 public static long StringToUnsignedInt (string value)
786                 {
787                         return XmlConvert.ToUInt32 (value);
788                 }
789
790                 public static decimal StringToUnsignedLong (string value)
791                 {
792                         return XmlConvert.ToUInt64 (value);
793                 }
794
795                 public static int StringToUnsignedShort (string value)
796                 {
797                         return XmlConvert.ToUInt16 (value);
798                 }
799
800                 public static TimeSpan StringToYearMonthDuration (string value)
801                 {
802                         return XmlConvert.ToTimeSpan (value);
803                 }
804
805                 public static string ItemToAnyUri (XPathItem value)
806                 {
807                         return value.Value;
808                 }
809
810                 public static byte [] ItemToBase64Binary (XPathItem value)
811                 {
812                         return Convert.FromBase64String (value.Value);
813                 }
814
815                 public static bool ItemToBoolean (XPathItem value)
816                 {
817                         return XmlConvert.ToBoolean (value.Value);
818                 }
819
820                 public static DateTime ItemToDate (XPathItem value)
821                 {
822                         return XmlConvert.ToDateTime (value.Value);
823                 }
824
825                 public static DateTime ItemToDateTime (XPathItem value)
826                 {
827                         return XmlConvert.ToDateTime (value.Value);
828                 }
829
830                 public static TimeSpan ItemToDayTimeDuration (XPathItem value)
831                 {
832                         return XmlConvert.ToTimeSpan (value.Value);
833                 }
834
835                 public static decimal ItemToDecimal (XPathItem value)
836                 {
837                         return XmlConvert.ToDecimal (value.Value);
838                 }
839
840                 public static double ItemToDouble (XPathItem value)
841                 {
842                         return XmlConvert.ToDouble (value.Value);
843                 }
844
845                 public static string ItemToDuration (XPathItem value)
846                 {
847                         return XmlConvert.ToString (XmlConvert.ToTimeSpan (value.Value));
848                 }
849
850                 public static float ItemToFloat (XPathItem value)
851                 {
852                         return XmlConvert.ToSingle (value.Value);
853                 }
854
855                 public static DateTime ItemToGDay (XPathItem value)
856                 {
857                         return XmlConvert.ToDateTime (value.Value);
858                 }
859
860                 public static DateTime ItemToGMonth (XPathItem value)
861                 {
862                         return XmlConvert.ToDateTime (value.Value);
863                 }
864
865                 public static DateTime ItemToGMonthDay (XPathItem value)
866                 {
867                         return XmlConvert.ToDateTime (value.Value);
868                 }
869
870                 public static DateTime ItemToGYear (XPathItem value)
871                 {
872                         return XmlConvert.ToDateTime (value.Value);
873                 }
874
875                 public static DateTime ItemToGYearMonth (XPathItem value)
876                 {
877                         return XmlConvert.ToDateTime (value.Value);
878                 }
879
880                 public static byte [] ItemToHexBinary (XPathItem value)
881                 {
882                         return XmlConvert.FromBinHexString (value.Value);
883                 }
884
885                 public static int ItemToInt (XPathItem value)
886                 {
887                         return XmlConvert.ToInt32 (value.Value);
888                 }
889
890                 public static long ItemToInteger (XPathItem value)
891                 {
892                         return XmlConvert.ToInt64 (value.Value);
893                 }
894
895                 public static XPathItem ItemToItem (XPathItem value, XmlSchemaType schemaTypeDest)
896                 {
897                         return new XPathAtomicValue (value.Value, schemaTypeDest);
898                 }
899
900                 public static decimal ItemToNonNegativeInteger (XPathItem value)
901                 {
902                         return XmlConvert.ToDecimal (value.Value);
903                 }
904
905                 public static decimal ItemToNonPositiveInteger (XPathItem value)
906                 {
907                         return XmlConvert.ToDecimal (value.Value);
908                 }
909
910                 public static XmlQualifiedName ItemToQName (XPathItem value)
911                 {
912                         return (XmlQualifiedName) value.TypedValue;
913                 }
914
915                 public static string ItemToString (XPathItem value)
916                 {
917                         if (value.ValueType == typeof (DateTime))
918                                 return XmlConvert.ToString ((DateTime) value.TypedValue);
919                         if (value.TypedValue is XmlQualifiedName)
920                                 throw new ArgumentException ("Invalid cast from schema QName type to string type.");
921                         return value.Value;
922                 }
923
924                 public static DateTime ItemToTime (XPathItem value)
925                 {
926                         return XmlConvert.ToDateTime (value.Value);
927                 }
928
929                 [MonoTODO]
930                 public static long ItemToUnsignedInt (XPathItem value)
931                 {
932                         // FIXME: signed
933                         return XmlConvert.ToInt32 (value.Value);
934                 }
935
936                 [MonoTODO]
937                 public static decimal ItemToUnsignedLong (XPathItem value)
938                 {
939                         // FIXME: signed
940                         return XmlConvert.ToInt32 (value.Value);
941                 }
942
943                 [MonoTODO]
944                 public static int ItemToUnsignedShort (XPathItem value)
945                 {
946                         // FIXME: signed
947                         return XmlConvert.ToInt32 (value.Value);
948                 }
949
950                 public static TimeSpan ItemToYearMonthDuration (XPathItem value)
951                 {
952                         return XmlConvert.ToTimeSpan (value.Value);
953                 }
954         }
955 }
956
957 #endif