I'm using this function to deserialise the data of the xml file:
Java
Uri uri = new Uri("/XML/ligne1_EUROPE.xml", UriKind.Relative);
XDocument document = XDocument.Load("XML/ligne1_EUROPE.xml");
XmlSerializer serializer = new XmlSerializer(typeof(Destinataires));
Destinataires ArretLoad = (Destinataires)serializer.Deserialize(document.CreateReader());
listBox.ItemsSource = ArretLoad.Collection;PowerShell
[XmlRoot("root")]
public class Destinataires
{
[XmlArray("Destinataires")]
[XmlArrayItem("Destinataire")]
[XmlArrayItem("Horraires")]
[XmlArrayItem("Horraire")]
public ObservableCollectionXML_Arret> Collection { get; set; }
}
And call the XML_Arret class
public class XML_Arret
{
[XmlElement("Designation")]
public string Designation { get; set; }
[XmlElement("Carre")]
public string Carre { get; set; }
[XmlElement("Horraires")]
public Horraires[] Horaires { get; set; }
public class Horraires
{
[XmlElement("Horraire")]
public string Horraire { get; set; }
}
}
My XML files is:
xml version="1.0" encoding="ISO-8859-1"?>
Faubourd d'isle
images/1.png
6h18
6h28
6h38
...
...
/root>
But when I debug my programm, I've this message:
Une exception de type 'System.InvalidOperationException' s'est produite dans System.Xml.Serialization.ni.dll
mais n'a pas été gérée dans le code utilisateur
à la ligne: XmlSerializer serializer = new XmlSerializer(typeof(Destinataires));
So, I'm lost, Do you can Help me?
And I'm sorry for my langage, I'm a french person.
Thanks
VulpesRank #55 · 29.2K reputationPosted Jul 18, 2014, 3:33 AM EDT
I think the problem here is that your XML attributes are not quite.
When I changed them to the following, your file deserialized correctly:
Ramesh MaruthiRank #937 · 2.2K reputationPosted Jul 17, 2014, 5:59 AM EDT
Can you try it in this way
Valentin Martin10 reputationPosted Jul 17, 2014, 6:07 AM EDT
My program doesn't work. I don't arrive to deserialise the Technical Control level
Ramesh MaruthiRank #937 · 2.2K reputationPosted Jul 17, 2014, 6:27 AM EDT
Did u write this lines in car class ?
Ramesh MaruthiRank #937 · 2.2K reputationPosted Jul 17, 2014, 6:39 AM EDT
Now I understood your problem you want do deserialize even the child nodes right ?
can you give try in this way
Valentin Martin10 reputationPosted Jul 17, 2014, 6:54 AM EDT
Ramesh MaruthiRank #937 · 2.2K reputationPosted Jul 17, 2014, 7:16 AM EDT
...
...
[XmlRoot("Destinataires")]
public class DestinatairesList
{
[XmlElement("Destinataire")]
public List
}
public class Destinatarie
{
[XmlElement("Designation")]
public string Designation { get; set; }
[XmlElement("Carre")]
public string Carre { get; set; }
[XmlElement("Horraires")]
public List
}
public class Horraire
{
[XmlElement("Horraire")]
public string Horraire { get; set; }
}
XmlSerializer deserializer = new XmlSerializer(typeof(DestinatarieDestinatarie));
TextReader reader = new StreamReader(@"D:\myXml.xml");
object obj = deserializer.Deserialize(reader);
Destinatarie XmlData = (Destinatarie)obj;
reader.Close();
Valentin Martin10 reputationPosted Jul 17, 2014, 12:30 PM EDT
I've try with your changement:
And for display Destinataire. Designation in my ListBox:
listBox1.ItemsSource = XmlData.Destinataire; ???
And:
But I've a problem: nothing appears on my screen. So I think I've a problem when I sent my data to the ListBox, or is in the DestinatairesList or Destinataire.
Ramesh MaruthiRank #937 · 2.2K reputationPosted Jul 18, 2014, 7:13 AM EDT
Try the Vulpes code, its working even for me :)
Thanks Vulpes sir :)
Valentin Martin10 reputationPosted Jul 18, 2014, 7:24 AM EDT
Thanks for your help !
VulpesRank #55 · 29.2K reputationPosted Jul 18, 2014, 3:31 PM EDT