Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Forcing a particular xml object serialization format
  2. StringWriter outStream = new StringWriter();
  3.    XmlSerializer s = new XmlSerializer(obj.GetType());
  4.    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
  5.    s.Serialize(outStream, obj, ns);
  6.    string xml = outStream.ToString();
  7.        
  8. public class Points
  9. {
  10.     [System.Xml.Serialization.XmlAttribute]
  11.     public string Type;
  12.     public double Number;
  13. }
  14.        
  15. <Points Type="Credit">123</Points>
  16.        
  17. public class Points
  18. {
  19.     [System.Xml.Serialization.XmlAttribute]
  20.     public string Type;
  21.     [System.Xml.Serialization.XmlText]
  22.     public double Number;
  23. }