XmlSerializer and xs:boolean value serialization

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am serializing a class containing boolean fields and noticed that values
are serialized (written on the XML file) as "True" and "False" (capitalised
first letter). However, when validating against a Schema, XMLSpy complains
xs:boolean only defines a "true" and "false" as valid values.

Is there any way XmlSerializer can be made to output those value without
having to write a customis serializer?

TIA,
Vanni
 
Can you demonstrate this with an example? The following works fine
(reports "false) targetting .NET 2.0.

Marc

using System;
using System.Xml.Serialization;

class Program
{
static void Main(string[] args)
{
XmlSerializer ser = new XmlSerializer(typeof(MyEntity));
MyEntity me = new MyEntity();
ser.Serialize(Console.Out, me);
me.IsValid = true;
ser.Serialize(Console.Out, me);
Console.ReadLine();
}
}
[Serializable]
public class MyEntity
{
private bool _isValid;
public bool IsValid { get { return _isValid; } set { _isValid =
value; } }
}
 
Hi Marc,

Thanks for the prompt reply. I think I found where the problem was, not in
the serialization but in a conversion component somebody else wrote, which
converts from a .NET .settings file-style XML (named element with "Value"
attribute) to a DOM where value is the element contents. For some reason,
some target XML files had "True" and "False" specified and that string was
passed in without normalising.

Regards.
v.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top