Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Deserialize XML document
    primarykey
    data
    text
    <p>How do I Deserialize this XML document:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Cars&gt; &lt;Car&gt; &lt;StockNumber&gt;1020&lt;/StockNumber&gt; &lt;Make&gt;Nissan&lt;/Make&gt; &lt;Model&gt;Sentra&lt;/Model&gt; &lt;/Car&gt; &lt;Car&gt; &lt;StockNumber&gt;1010&lt;/StockNumber&gt; &lt;Make&gt;Toyota&lt;/Make&gt; &lt;Model&gt;Corolla&lt;/Model&gt; &lt;/Car&gt; &lt;Car&gt; &lt;StockNumber&gt;1111&lt;/StockNumber&gt; &lt;Make&gt;Honda&lt;/Make&gt; &lt;Model&gt;Accord&lt;/Model&gt; &lt;/Car&gt; &lt;/Cars&gt; </code></pre> <p>I have this:</p> <pre><code>[Serializable()] public class Car { [System.Xml.Serialization.XmlElementAttribute("StockNumber")] public string StockNumber{ get; set; } [System.Xml.Serialization.XmlElementAttribute("Make")] public string Make{ get; set; } [System.Xml.Serialization.XmlElementAttribute("Model")] public string Model{ get; set; } } </code></pre> <p>.</p> <pre><code>[System.Xml.Serialization.XmlRootAttribute("Cars", Namespace = "", IsNullable = false)] public class Cars { [XmlArrayItem(typeof(Car))] public Car[] Car { get; set; } } </code></pre> <p>.</p> <pre><code>public class CarSerializer { public Cars Deserialize() { Cars[] cars = null; string path = HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data/") + "cars.xml"; XmlSerializer serializer = new XmlSerializer(typeof(Cars[])); StreamReader reader = new StreamReader(path); reader.ReadToEnd(); cars = (Cars[])serializer.Deserialize(reader); reader.Close(); return cars; } } </code></pre> <p>that don't seem to work :-(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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