title: Serialization of optional items
body: <p>I have a 137 XML files to deserialize.
  Each of them contains one tv channel and programs that are broadcast by.
  Each program may have some additional information.
  For example:
  actors, presenters, duration, quality, resolution, country producers and so on.</p>
  
  <p>So I have these options:
  The specified tag does not exist in the file.
  The specified tag could exist, but will not have a value.</p>
  
  <p>How to include this information in class, to which I want to serialize the xml?
  I want to have one class for all variants.
  I created a class that contains all possible tags. 
  Automatically generate in VS 2013- </p>
  
  <pre><code>Edit&gt; Paste Special&gt; Paste Xml as a class. 
  </code></pre>
  
  <p>For the programs joined with various tags in a xml.
  Items are nullable.</p>
  
  <pre><code>[XmlElement (IsNullable = true)]
  </code></pre>
  
  <p>But how to tell the program that some tags may not be at all in the program?</p>
  
  <p>I checked how many variants of the occurrence of tags in each file.
  There are 34 It's too much for me to generate them as separate classes and during serialization chose the class, which are to be serialized.</p>
  
  <p>EDIT 1</p>
  
  <p>xml is like this</p>
  
  <pre><code>&lt;tv&gt;
   &lt;channel&gt;
   &lt;programme&gt;
   &lt;programme&gt;
   &lt;programme&gt;
  &lt;tv&gt;
  </code></pre>
  
  <p>And for example, such programs may happen. I want to handle both.</p>
  
  <pre><code>  &lt;programme channel="85" start="20140604080000 +0200" stop="20140604083500 +0200"&gt;
      &lt;title&gt;Peaceforce&lt;/title&gt;
      &lt;desc&gt;Kopenhaga, rok 2045. Światem wstrząsają kolejne wojny. Pewien cywil prosi żołnierza o zastrzelenie słonia, który wydostał się na wolność. Rozwścieczone zwierzę niszczy i zabija wszystko na swojej drodze. Wg George'a Orwella.&lt;/desc&gt;
      &lt;credits&gt;
        &lt;director&gt;Peter Gornstein&lt;/director&gt;
        &lt;actor&gt;Cyron Melville&lt;/actor&gt;
        &lt;actor&gt;Henning Jensen&lt;/actor&gt;
        &lt;actor&gt;André Babikian&lt;/actor&gt;
        &lt;actor&gt;Silja Byske&lt;/actor&gt;
        &lt;writer&gt;David Sandreuter&lt;/writer&gt;
      &lt;/credits&gt;
      &lt;date&gt;2010&lt;/date&gt;
      &lt;category&gt;10&lt;/category&gt;
      &lt;language&gt;PL&lt;/language&gt;
      &lt;length units="minutes"&gt;19&lt;/length&gt;
      &lt;country&gt;Dania&lt;/country&gt;
      &lt;video&gt;
        &lt;aspect&gt;16:9&lt;/aspect&gt;
      &lt;/video&gt;
      &lt;rating system="dvb"&gt;
        &lt;value&gt;9&lt;/value&gt;
      &lt;/rating&gt;
    &lt;/programme&gt;
  </code></pre>
  
  <p>They are from different xml.</p>
  
  <pre><code>  &lt;programme channel="337" start="20140604060000 +0200" stop="20140604090000 +0200"&gt;
      &lt;title&gt;Popbudzik&lt;/title&gt;
      &lt;desc&gt;Poranny program, w którym emitowana jest głośna i pobudzająca muzyka.&lt;/desc&gt;
      &lt;category&gt;60&lt;/category&gt;
      &lt;language&gt;PL&lt;/language&gt;
      &lt;country&gt;Polska&lt;/country&gt;
      &lt;video&gt;
        &lt;aspect&gt;16:9&lt;/aspect&gt;
      &lt;/video&gt;
      &lt;audio&gt;
        &lt;stereo&gt;stereo&lt;/stereo&gt;
      &lt;/audio&gt;
      &lt;rating system="dvb"&gt;
        &lt;value&gt;9&lt;/value&gt;
      &lt;/rating&gt;
    &lt;/programme&gt;
  </code></pre>
  
  <p>Xml header for second xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE tv SYSTEM "xmltv.dtd"&gt;
  &lt;tv generator-info-name="akpa"&gt;
    &lt;channel id="337"&gt;
      &lt;display-name&gt;4fun.tv&lt;/display-name&gt;
    &lt;/channel&gt;
  </code></pre>