title: C# XML & JSON serialization of a class include / exclude properties differently in each format
body: <p>I'm am trying to serialize a class into both XML &amp; JSON.</p>
  
  <p>This is rather trivial, however I need to exclude some properties that are included in the XML output from the output of the JSON. </p>
  
  <p>For example :</p>
  
  <pre>
  [DataContract]
  public class Foobar
  {
      [DataMember]
      [XmlElement("somestr")]
      public string SomeString
  
      [XmlElement("otherstr")]
      public string OtherString
  
  }
  </pre>
  
  <p>Now normally, when not using [XmlElement("tag_name")], simply omitting [DataContract] on a property is sufficient to exclude "OtherString" it when serialized to JSON.</p>
  
  <p>My tests appear to show that the [XmlElement] directive is telling the JSON serializer to include them. </p>
  
  <p>Has anyone got any suggestions on how I can go about controling the output so that it's different for JSON &amp; XML?</p>
  
  <p>Many thanks.</p>