XmlSerializer - object to string returning "p2:nill" instead of xsi:nill

511 Views Asked by At

After Serialzation, object to a string

I am getting the current xml

  <obj>
    ...
    <field p2:nil="true" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance"/>
    ...
  </obj>

the field is nullable so i am waiting for an xsi:nill, instead i am getting p2:nill why?

1

There are 1 best solutions below

0
On

When building an XmlSerializer you can control the namespaces, if you don't random(ish) names will be applied. Try seeing if something like this helps

var ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

var ser = new XmlSerializer(typeof(AnEntity));
ser.Serialize(Console.Out, new AnEntity(), ns);