0

I'm using the C# serialization on one of my objects:

   StringWriter outStream = new StringWriter();
   XmlSerializer s = new XmlSerializer(obj.GetType());
   XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
   s.Serialize(outStream, obj, ns);
   string xml = outStream.ToString();

The object is:

public class Points
{
    [System.Xml.Serialization.XmlAttribute]
    public string Type;
    public double Number;
}

My Points class is being used by another program expecting it in the form:

 <Points Type="Credit">123</Points>

I was trying to work if I can use any attributes to force this format?

Thanks

Yahia
  • 69,653
  • 9
  • 115
  • 144
probably at the beach
  • 14,489
  • 16
  • 75
  • 116

1 Answers1

1

I think you need to use the [System.Xml.Serialization.XmlText] attribute on the Number field, like you do with the XmlAttribute on the type:

public class Points
{
    [System.Xml.Serialization.XmlAttribute]
    public string Type;
    [System.Xml.Serialization.XmlText]
    public double Number;
}
Avner Shahar-Kashtan
  • 14,492
  • 3
  • 37
  • 63