Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserialization from XML to List Object
    primarykey
    data
    text
    <p>I am doing the program in convert XML file to List Objects. I have successfully done serialization from List to XML .but I have an problem on doing deserialization. Please anyone tell me what's the wrong i have done in this code. </p> <p>This is my XML code. </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;Contact_x0020_Form xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;Contact&gt; &lt;Contact&gt; &lt;Id&gt;1&lt;/Id&gt; &lt;Name&gt;vicky1kumar&lt;/Name&gt; &lt;Phone&gt;248847227&lt;/Phone&gt; &lt;/Contact&gt; &lt;Contact&gt; &lt;Id&gt;2&lt;/Id&gt; &lt;Name&gt;vicky1kumar2kumar&lt;/Name&gt; &lt;Phone&gt;725228355&lt;/Phone&gt; &lt;/Contact&gt; &lt;Contact&gt; &lt;Id&gt;3&lt;/Id&gt; &lt;Name&gt;vicky1kumar2kumar3kumar&lt;/Name&gt; &lt;Phone&gt;2032848116&lt;/Phone&gt; &lt;/Contact&gt; &lt;Contact&gt; &lt;Id&gt;4&lt;/Id&gt; &lt;Name&gt;vicky1kumar2kumar3kumar4kumar&lt;/Name&gt; &lt;Phone&gt;853938969&lt;/Phone&gt; &lt;/Contact&gt; &lt;Contact&gt; &lt;Id&gt;5&lt;/Id&gt; &lt;Name&gt;vicky1kumar2kumar3kumar4kumar5kumar&lt;/Name&gt; &lt;Phone&gt;530646891&lt;/Phone&gt; &lt;/Contact&gt; &lt;/Contact&gt; &lt;Id&gt;0&lt;/Id&gt; &lt;/Contact_x0020_Form&gt; </code></pre> <p>This is my Class for convert XML to List Object </p> <pre><code>public class Converter { public static T XmlToObject&lt;T&gt;(string xml) { using (var xmlStream = new StringReader(xml)) { var serializer = new XmlSerializer(typeof(T)); return (T)serializer.Deserialize(XmlReader.Create(xmlStream)); } } public static List&lt;T&gt; XmlToObjectList&lt;T&gt;(string xml, string nodePath) { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xml); var returnItemsList = new List&lt;T&gt;(); foreach (XmlNode xmlNode in xmlDocument.SelectNodes(nodePath)) { returnItemsList.Add(XmlToObject&lt;T&gt;(xmlNode.OuterXml)); } return returnItemsList; } } </code></pre> <p>And this is my DEserialization code... </p> <pre><code>List&lt;string&gt; decont = new List&lt;string&gt;(); decont = Converter.XmlToObjectList&lt;string&gt;(@"C:\vignesh\serialization\xmlserialize\XmlSerializeContact.xml","//Contact"); foreach (var item in decont) { Console.WriteLine(decont); } </code></pre> <p>I got this error:</p> <blockquote> <p>Data at the root level is invalid. Line 1, position 1. </p> </blockquote>
    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