Boolean values are not handled correctly


Type of boolean values should be lowercased when using toString() method. Uppercase values generate an invalid xml which is not validated against schemas with boolean values. Valid values are: "true", "false", "0", "1".

At least it fails when using boolean simple type list.


RolandasR wrote Apr 16, 2013 at 5:48 PM

Clearing the issue a bit. All simple type lists use toString() method in XObjects class when saving final Value for XElement. Almost all simple lists do a bad thing when new values are added. An example of such schema:
  <xs:simpleType name="bitList">
    <xs:list itemType="bit" />
  <xs:simpleType name="bit">
    <xs:restriction base="xs:boolean" />
The same happens with all dates/times as well. As a workaround, one could use rootElement.Untyped.SetValue() method to fix an issue.

RolandasR wrote Apr 16, 2013 at 6:11 PM

The buggy code is in SimpleTypeValidator.cs file, class ListSimpleTypeValidator, method:
        internal static string ToString(object value) {
            Debug.Assert(value is IEnumerable);
            IEnumerable list = (IEnumerable)value;
            StringBuilder bldr = new StringBuilder();

            foreach (object o in list) {
                // Separate values by single space character
                if (bldr.Length != 0)
                    bldr.Append(' ');
                bldr.Append(o.ToString()); // <-- bad things happen here
            return bldr.ToString();

sergey_shandar wrote Nov 7, 2013 at 4:03 AM