Note that there are some explanatory texts on larger screens.

plurals
  1. POXML Deserialization inner exception
    primarykey
    data
    text
    <p>I am trying to deserialize an XML file to a class. The XML file looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;locations&gt; &lt;location id="0"&gt; &lt;name&gt;park&lt;/name&gt; &lt;temperature&gt;5&lt;/temperature&gt; &lt;wind&gt;26&lt;/wind&gt; &lt;weather_text_SI&gt;sunny&lt;/weather_text_SI&gt; &lt;visibility&gt;&lt;/visibility&gt; &lt;latitude&gt;46.4527&lt;/latitude&gt; &lt;longitude&gt;15.334&lt;/longitude&gt; &lt;elevation&gt;1517&lt;/elevation&gt; &lt;/location&gt; &lt;/locations&gt; </code></pre> <p>The class that I want to deserialize it to is:</p> <pre><code>[XmlRootAttribute("locations")] public class SnowPark { public SnowPark() { } private int id; [XmlAttribute("id")] public int Id { get { return id; } set { id = value; } } private string name; [XmlElement("name")] public string Name { get { return name; } set { name = value; } } private int temperature; [XmlElement("temperature")] public int Temperature { get { return temperature; } set { temperature = value; } } private int wind; [XmlElement("wind")] public int Wind { get { return wind; } set { wind = value; } } private string weatherText; [XmlElement("weather_text_SI")] public string WeatherText { get { return weatherText; } set { weatherText = value; } } private double latitude; [XmlElement("latitude")] public double Latitude { get { return latitude; } set { latitude = value; } } private double longitude; [XmlElement("longitude")] public double Longitude { get { return longitude; } set { longitude = value; } } private int elevation; [XmlElement("elevation")] public int Elevation { get { return elevation; } set { elevation = value; } } } </code></pre> <p>I try to deserialize the XML file</p> <pre><code>XmlSerializer deserializer = new XmlSerializer(typeof(List&lt;SnowPark&gt;)); TextReader textReader = new StreamReader(@"file.xml"); List&lt;SnowPark&gt; parks; parkss = (List&lt;SnowPark&gt;)deserializer.Deserialize(textReader); textReader.Close(); </code></pre> <p>However I get an exception:</p> <pre><code>There is an error in XML document (2, 2). </code></pre> <p>and an inner exception:</p> <pre><code>&lt;locations xmlns=''&gt; was not expected. </code></pre> <p>No luck finding the solution so far. Help appreciated.</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