Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Deserialize XML to object: There is an error in XML document (3, 2)
    primarykey
    data
    text
    <p>I'm trying to deserialize XML into a C# object</p> <p>I am getting the error:There is an error in XML document (3, 2).</p> <p>Cannot seem to fix it! Here is the code:</p> <p>The XSD is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;!--Created with Liquid XML Studio 2012 Developer Edition (Trial) 10.0.2.3955 (http://www.liquid-technologies.com)--&gt; &lt;xs:schema xmlns:tns="http://www.adamroe.com/xsd/cameras.xsd" elementFormDefault="qualified" targetNamespace="http://www.adamroe.com/xsd/cameras.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="CameraBase"&gt; &lt;xs:complexType&gt; &lt;xs:sequence minOccurs="1" maxOccurs="1"&gt; &lt;xs:element name="Cameras"&gt; &lt;xs:complexType&gt; &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt; &lt;xs:element name="Camera" type="tns:CameraType" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:complexType name="CameraType"&gt; &lt;xs:sequence&gt; &lt;xs:element name="Make" type="xs:string" /&gt; &lt;xs:element name="Model" type="xs:string" /&gt; &lt;xs:element name="Variable1" type="xs:double" /&gt; &lt;xs:element name="Variable2" type="xs:double" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:schema&gt; </code></pre> <p>The XML is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- Created with Liquid XML Studio 2012 Developer Edition (Trial) 10.0.2.3955 (http://www.liquid-technologies.com) --&gt; &lt;aroe:CameraBase xmlns:aroe="http://www.adamroe.com/xsd/cameras.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.adamroe.com/xsd/cameras.xsd C:\Users\Adam\Desktop\Cameras.xsd"&gt; &lt;aroe:Cameras&gt; &lt;aroe:Camera&gt; &lt;aroe:Make&gt;SONY&lt;/aroe:Make&gt; &lt;aroe:Model&gt;DSC-W130&lt;/aroe:Model&gt; &lt;aroe:Variable1&gt;0.6352&lt;/aroe:Variable1&gt; &lt;aroe:Variable2&gt;22.375&lt;/aroe:Variable2&gt; &lt;/aroe:Camera&gt; &lt;aroe:Camera&gt; &lt;aroe:Make&gt;Panasonic&lt;/aroe:Make&gt; &lt;aroe:Model&gt;DMC-FX30&lt;/aroe:Model&gt; &lt;aroe:Variable1&gt;0.8869&lt;/aroe:Variable1&gt; &lt;aroe:Variable2&gt;24.73&lt;/aroe:Variable2&gt; &lt;/aroe:Camera&gt; &lt;aroe:Camera&gt; &lt;aroe:Make&gt;Olympus&lt;/aroe:Make&gt; &lt;aroe:Model&gt;X450&lt;/aroe:Model&gt; &lt;aroe:Variable1&gt;0.6003&lt;/aroe:Variable1&gt; &lt;aroe:Variable2&gt;20.654&lt;/aroe:Variable2&gt; &lt;/aroe:Camera&gt; &lt;aroe:Camera&gt; &lt;aroe:Make&gt;Fujifilm&lt;/aroe:Make&gt; &lt;aroe:Model&gt;FinePix S9600&lt;/aroe:Model&gt; &lt;aroe:Variable1&gt;1.0024&lt;/aroe:Variable1&gt; &lt;aroe:Variable2&gt;35.704&lt;/aroe:Variable2&gt; &lt;/aroe:Camera&gt; &lt;aroe:Camera&gt; &lt;aroe:Make&gt;Canon&lt;/aroe:Make&gt; &lt;aroe:Model&gt;EOS 400D&lt;/aroe:Model&gt; &lt;aroe:Variable1&gt;1.5143&lt;/aroe:Variable1&gt; &lt;aroe:Variable2&gt;69.409&lt;/aroe:Variable2&gt; &lt;/aroe:Camera&gt; &lt;/aroe:Cameras&gt; &lt;/aroe:CameraBase&gt; </code></pre> <p>The class is:</p> <pre><code>public class Camera { public string Make; public string Model; public double Variable1; public double Variable2; } </code></pre> <p>Deserialize code:</p> <pre><code>public class PopulateXML { public void DeserializeObject(string filenameXML) { Console.WriteLine("Reading with XmlReader"); // Create an instance of the XmlSerializer specifying type and namespace. XmlSerializer serializer = new XmlSerializer(typeof(List&lt;Camera&gt;)); // A FileStream is needed to read the XML document. FileStream fs = new FileStream(filenameXML, FileMode.Open); XmlReader reader = new XmlTextReader(fs); // Declare an object variable of the type to be deserialized. List&lt;Camera&gt; i; // Use the Deserialize method to restore the object's state. i = (List&lt;Camera&gt;)serializer.Deserialize(reader); } } </code></pre> <p>Main:</p> <pre><code>PopulateXML x = new PopulateXML(); // Read a purchase order. x.DeserializeObject("Cameras.xml"); </code></pre> <p>The exception is thrown on: i = (List)serializer.Deserialize(reader);</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.
 

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