3
votes

I was pleasantly surprised to find the the XmlProvider tries to infers types. But I have run into a problem. There is an xml element whose value is 5.25.2. I would like it's type to be string. But XmlProvider seems to infer it to DateTime.

Is there a way to override the type for specific xml elements?

For now, I am working around by setting InferTypesFromValues=false.

> sample.Scan.ScannerVersion.Value;;
val it : System.DateTime =
  5/25/2002 12:00:00 AM {Date = 5/25/2002 12:00:00 AM;
                         Day = 25;
                         DayOfWeek = Saturday;
                         DayOfYear = 145;
                         Hour = 0;
                         Kind = Local;
                         Millisecond = 0;
                         Minute = 0;
                         Month = 5;
                         Second = 0;
                         Ticks = 631578816000000000L;
                         TimeOfDay = 00:00:00;
                         Year = 2002;}
1
Somewhat depending on the case, I have at some points "cheated" and made sure that the example its infering from, does contain something thats clearly not ambigious. In this case you could add some data in this Xml-file where it can not be taken for a date in this spesific field. - Helge Rene Urholm

1 Answers

1
votes

It seems to me your options are to either:

  • Provide your own xml snippet that serves as a spec, so that you can better influence the inferred types.
  • Use the InferTypesFromValues=false parameter to the XmlProvider so that all properties are just of type string.

In the second case, this might look like

type Things = XmlProvider<MySample, InferTypesFromValues=false>

I hope this helps.