Deserialize an XML file - an error in xml document (1,2)

Posted by Lindsay Fisher on Stack Overflow See other posts from Stack Overflow or by Lindsay Fisher
Published on 2012-02-28T10:33:11Z Indexed on 2012/09/09 3:38 UTC
Read the original article Hit count: 508

Filed under:
|
|

I'm trying to deserialize an XML file which I receive from a vendor with XmlSerializer, however im getting this exception: There is an error in XML document (1, 2).InnerException Message "<delayedquotes xmlns=''> was not expected.. I've searched the stackoverflow forum, google and implemented the advice, however I'm still getting the same error. Please find the enclosed some content of the xml file:

<delayedquotes id="TestData">
  <headings>
    <title/>
    <bid>bid</bid>
    <offer>offer</offer>
    <trade>trade</trade>
    <close>close</close>
    <b_time>b_time</b_time>
    <o_time>o_time</o_time>
    <time>time</time>
    <hi.lo>hi.lo</hi.lo>
    <perc>perc</perc>
    <spot>spot</spot>
  </headings>
  <instrument id="Test1">
    <title id="Test1">Test1</title>
    <bid>0</bid>
    <offer>0</offer>
    <trade>0</trade>
    <close>0</close>
    <b_time>11:59:00</b_time>
    <o_time>11:59:00</o_time>
    <time>11:59:00</time>
    <perc>0%</perc>
    <spot>0</spot>
  </instrument>
</delayedquotes>

and the code

[Serializable, XmlRoot("delayedquotes"), XmlType("delayedquotes")]
public class delayedquotes
{
    [XmlElement("instrument")]
    public string instrument { get; set; }
    [XmlElement("title")]
    public string title { get; set; }
    [XmlElement("bid")]
    public double bid { get; set; }
    [XmlElement("spot")]
    public double spot { get; set; }
    [XmlElement("close")]
    public double close { get; set; }
    [XmlElement("b_time")]
    public DateTime b_time { get; set; }
    [XmlElement("o_time")]
    public DateTime o_time { get; set; }
    [XmlElement("time")]
    public DateTime time { get; set; }
    [XmlElement("hi")]
    public string hi { get; set; }
    [XmlElement("lo")]
    public string lo { get; set; }
    [XmlElement("offer")]
    public double offer { get; set; }
    [XmlElement("trade")]
    public double trade { get; set; }

    public delayedquotes()
    {

    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml