У меня проблема. Я получаю следующее XML с моей веб-страницы:
<data>
<sets>
<set>
<name>Set A</name>
<price>7.5</price>
<pictures>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<size>1X 13X18 + 1X 10X15 + 6 pasfotos op 20X30,5</size>
<price>7.50</price>
<quantity>1</quantity>
</picture>
</pictures>
</set>
<set>
<name>Set B</name>
<price>14.45</price>
<pictures>
<picture>
<id>4</id>
<name>Potret2.jpg</name>
<size>13 x 18 mat</size>
<price>6.95</price>
<quantity>1</quantity>
</picture>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<size>1X 13X18 + 1X 10X15 + 6 pasfotos op 20X30,5</size>
<price>7.50</price>
<quantity>1</quantity>
</picture>
</pictures>
</set>
<set>
<name>Set C</name>
<price>13.9</price>
<pictures>
<picture>
<id>4</id>
<name>Potret2.jpg</name>
<size>13 x 18 mat</size>
<price>6.95</price>
<quantity>2</quantity>
</picture>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<size>13 x 18 mat</size>
<price>6.95</price>
<quantity>1</quantity>
</picture>
</pictures>
</set>
<set>
<name>Set D</name>
<price>14.45</price>
<pictures>
<picture>
<id>1</id>
<name>GroepsFoto.jpg</name>
<size>Groepsfoto 13 x 18 mat</size>
<price>6.95</price>
<quantity>1</quantity>
</picture>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<size>1X 13X18 + 1X 10X15 + 6 pasfotos op 20X30,5</size>
<price>7.50</price>
<quantity>1</quantity>
</picture>
</pictures>
</set>
<set>
<name>Set E</name>
<price>21.4</price>
<pictures>
<picture>
<id>1</id>
<name>GroepsFoto.jpg</name>
<size>Groepsfoto 13 x 18 mat</size>
<price>6.95</price>
<quantity>1</quantity>
</picture>
<picture>
<id>4</id>
<name>Potret2.jpg</name>
<size>13 x 18 mat</size>
<price>6.95</price>
<quantity>1</quantity>
</picture>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<size>1X 13X18 + 1X 10X15 + 6 pasfotos op 20X30,5</size>
<price>7.50</price>
<quantity>1</quantity>
</picture>
</pictures>
</set>
<set>
<name>Set F</name>
<price>21.4</price>
<pictures>
<picture>
<id>1</id>
<name>GroepsFoto.jpg</name>
<size>Groepsfoto 13 x 18 mat</size>
<price>6.95</price>
<quantity>1</quantity>
</picture>
<picture>
<id>4</id>
<name>Potret2.jpg</name>
<size>13 x 18 mat</size>
<price>6.95</price>
<quantity>2</quantity>
</picture>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<size>1X 13X18 + 1X 10X15 + 6 pasfotos op 20X30,5</size>
<price>7.50</price>
<quantity>1</quantity>
</picture>
</pictures>
</set>
</sets>
<pictures>
<picture>
<id>5</id>
<name>Potret2Pasfoto.jpg</name>
<sizes>
<size>
<id>1</id>
<name>1X 13X18 + 1X 10X15 + 6 pasfotos op 20X30,5</name>
<price>7.50</price>
</size>
</sizes>
</picture>
<picture>
<id>4</id>
<name>Potret2.jpg</name>
<sizes>
<size>
<id>2</id>
<name>13 x 18 mat</name>
<price>6.95</price>
</size>
<size>
<id>4</id>
<name>10 x 15 mat</name>
<price>6.50</price>
</size>
<size>
<id>13</id>
<name>20 x 28 mat</name>
<price>9.75</price>
</size>
<size>
<id>14</id>
<name>30 x 45 mat</name>
<price>25.00</price>
</size>
<size>
<id>15</id>
<name>40 x 60 mat</name>
<price>45.00</price>
</size>
<size>
<id>16</id>
<name>50 x 70 mat</name>
<price>57.50</price>
</size>
<size>
<id>17</id>
<name>canvas+opspannen 20 x 28</name>
<price>32.50</price>
</size>
<size>
<id>18</id>
<name>canvas+opspannen 30 x 45</name>
<price>42.50</price>
</size>
<size>
<id>19</id>
<name>canvas+opspannen 40 x 60</name>
<price>59.50</price>
</size>
<size>
<id>20</id>
<name>canvas+opspannen 50 x 70</name>
<price>72.50</price>
</size>
<size>
<id>21</id>
<name>canvas+opspannen 60 x 80</name>
<price>85.00</price>
</size>
<size>
<id>22</id>
<name>canvas+opspannen 70 x 100</name>
<price>99.00</price>
</size>
</sizes>
</picture>
<picture>
<id>1</id>
<name>GroepsFoto.jpg</name>
<sizes>
<size>
<id>2</id>
<name>13 x 18 mat</name>
<price>6.95</price>
</size>
<size>
<id>4</id>
<name>10 x 15 mat</name>
<price>6.50</price>
</size>
<size>
<id>13</id>
<name>20 x 28 mat</name>
<price>9.75</price>
</size>
<size>
<id>14</id>
<name>30 x 45 mat</name>
<price>25.00</price>
</size>
<size>
<id>15</id>
<name>40 x 60 mat</name>
<price>45.00</price>
</size>
<size>
<id>16</id>
<name>50 x 70 mat</name>
<price>57.50</price>
</size>
<size>
<id>17</id>
<name>canvas+opspannen 20 x 28</name>
<price>32.50</price>
</size>
<size>
<id>18</id>
<name>canvas+opspannen 30 x 45</name>
<price>42.50</price>
</size>
<size>
<id>19</id>
<name>canvas+opspannen 40 x 60</name>
<price>59.50</price>
</size>
<size>
<id>20</id>
<name>canvas+opspannen 50 x 70</name>
<price>72.50</price>
</size>
<size>
<id>21</id>
<name>canvas+opspannen 60 x 80</name>
<price>85.00</price>
</size>
<size>
<id>22</id>
<name>canvas+opspannen 70 x 100</name>
<price>99.00</price>
</size>
</sizes>
</picture>
</pictures>
</data>
Итак, я создал класс, который создается для анализа XML в. Вот класс, который я создал:
[XmlRoot("data")]
public class MyData
{
[XmlArray("sets")]
[XmlArrayItem("set")]
public List<set> Sets { get; } = new List<set>();
[XmlArray("pictures")]
[XmlArrayItem("picture")]
public List<SinglePicture> Fotos { get; } = new List<SinglePicture>();
}
public class set
{
[XmlArray("pictures")]
[XmlArrayItem("picture")]
public List<PictureInSet> pictures { get; set; } = new List<PictureInSet>();
public string name { get; set; }
public float price { get; set; }
}
public class PictureInSet
{
public int id { get; set; }
public string name { get; set; }
public string size { get; set; }
public float price { get; set; }
public int quantity { get; set; }
}
public class SinglePicture
{
public int id { get; set; }
public string name { get; set; }
[XmlArray("sizes")]
[XmlArrayItem("size")]
public List<size> sizes { get; set; } = new List<size>();
}
public class size
{
public int id { get; set; }
public string name { get; set; }
public float price { get; set; }
}
Но когда я пытаюсь проанализировать его с помощью следующего кода:
var xmlString = await response.Content.ReadAsStringAsync();
var ser = new XmlSerializer(typeof(MyData));
var data = (MyData)ser.Deserialize(new StringReader(xmlString));
App.lstSets = data.Sets;
App.lstPictures = data.Pictures;
оба списка пусты. Я сделал этот класс с помощью специальной вставки, но изменил несколько вещей, которые были вставлены без необходимости.
Что я делаю не так?