Note that there are some explanatory texts on larger screens.

plurals
  1. POOptionally omit namespace from xml on deserialization?
    primarykey
    data
    text
    <p>I want the option to omit the xmlns:xsi, xmlns:xsd and xmlns attributes from xml content. When doing so deserialization is failing.</p> <p>This is the xsd definition:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsd:schema id="CSVDataPluginConfig" targetNamespace="http://tempuri.org/CSVDataPluginConfig.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/CSVDataPluginConfig.xsd" xmlns:mstns="http://tempuri.org/CSVDataPluginConfig.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" &gt; &lt;xsd:element name="CSVDataPluginConfig" type="CSVDataPluginConfig"/&gt; &lt;xsd:complexType name="CSVDataPluginConfig"&gt; ... &lt;/xsd:complexType&gt; &lt;/xsd:schema&gt; </code></pre> <p>The xsd.exe code generator is giving this:</p> <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute( Namespace="http://tempuri.org/CSVDataPluginConfig.xsd")] [System.Xml.Serialization.XmlRootAttribute( Namespace="http://tempuri.org/CSVDataPluginConfin.xsd", IsNullable=false)] public partial class CSVDataPluginConfig { } </code></pre> <p>This is the sample of xml content that deserializes successfully:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt; &lt;CSVDataPluginConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/CSVDataPluginConfig.xsd"&gt; ... &lt;/CSVDataPluginConfig&gt; </code></pre> <p>For simplicity and making it easier to handwrite the xml, I want to be able to successfully deserialize the following:</p> <pre><code>&lt;CSVDataPluginConfig&gt; ... &lt;/CSVDataPluginConfig&gt; </code></pre> <p>I am deserializing using this extension method:</p> <pre><code> public static T DeserializeXML&lt;T&gt;(this string xml) { T obj; using (StringReader reader = new StringReader(xml)) { obj = (T)new XmlSerializer(typeof(T)).Deserialize(reader); reader.Close(); } return obj; } </code></pre> <p>Using Visual Studio 2008, what are my options, and what is the best option?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload