i have the following xml (which i can not edit):
<?xml version="1.0" encoding="UTF-8"?>
<ns0:prices xmlns:ns0="http://schemas.some.com/sadas/Output">
<pricepoint>
<esid>
ENG.GPL.DAY_AHEAD.PROMPT.PH.M
</esid>
<observationdate>20120123</observationdate>
<observationtime>0000</observationtime>
<price>22.1250</price>
<quote>Q</quote>
</pricepoint>
<pricepoint>
<esid>
ENG.NBP.DAY_AHEAD.PROMPT.PH.M
</esid>
<observationdate>20120123</observationdate>
<observationtime>0000</observationtime>
<price>53.8500</price>
<quote>Q</quote>
</pricepoint>
<pricepoint>
<esid>
ENG.NCG.DAY_AHEAD.PROMPT.PH.M
</esid>
<observationdate>20120123</observationdate>
<observationtime>0000</observationtime>
<price>22.0750</price>
<quote>Q</quote>
</pricepoint>
<pricepoint>
<esid>
ENG.TTF.DAY_AHEAD.PROMPT.PH.M
</esid>
<observationdate>20120123</observationdate>
<observationtime>0000</observationtime>
<price>21.9500</price>
<quote>Q</quote>
</pricepoint>
<pricepoint>
<esid>
ENG.ZEEBRUGGE.DAY_AHEAD.PROMPT.PH.M
</esid>
<observationdate>20120123</observationdate>
<observationtime>0000</observationtime>
<price>53.6500</price>
<quote>Q</quote>
</pricepoint>
</ns0:prices>
and the following object i want to map it to:
[Serializable]
public class Prices
{
public List<Pricepoint> prices { get; set; }
}
[Serializable]
public class Pricepoint
{
public string Esid { get; set; }
public DateTime Observationdate { get; set; }
public int Observationtime { get; set; }
public double Price { get; set; }
public string Quote { get; set; }
}
Using the following method:
public static object Deserialize(Type typeToDeserialize,byte[] bytes)
{
var mem = new MemoryStream(bytes);
var ser = new XmlSerializer(typeToDeserialize);
return ser.Deserialize(mem);
}
which is invoed by Deserialize(typeof(Prices), byteArrayofXMLfile);
I do however get an error regarding the namespace line of the xml:
There is an error in XML document (3, 2)
I cant figure out what i am doing wrong here?
resolved the problem by letting visual studio generating the classes for me: