title: Deserialize XML without knowing type
body: <p>I have a database-column that contains some XML-data as a string. Hence I do not know the actual type that is represented by this xml I want to read the root-tag of this XML and than deserialize the complete content with this type. Because the embedded XML may be quite large and the table contains some thousand of these objects I need a fast solution for this. My first approach was on simply extracting the root-tag using some string-magic (probably using Regex), get the type by calling <code>Type.GetType</code> and then create the serializer for this type. But than I had a look on <code>XMLReader</code> which also supports a <code>ValueType</code>-property. </p>
  
  <pre><code>using (XmlReader reader = XmlReader.Create(new StringReader(myXmlAsString)))
  {
      reader.MoveToContent(); // get the root-element
      Type type = reader.ValueType;
  
      XmlSerializer ser = new XmlSerializer(type);
      return ser.Deserialize(reader);
  }
  </code></pre>
  
  <p>The problem I have to face is that <code>reader.ValueType</code> always returns string-type rather then the type represented by the root-tag. </p>
  
  <p>Finally: which of the two solutions would be faster? Bottleneck on first one is supposed to be the regex-engine to get the tapeName, on second approach it might be reader-operations. </p>