Jest to strumień xml:deserialising nie działa
<?xml version="1.0" encoding="utf-8" ?>
<historydetails>
<taskEvent>
<eventtype>Transitions</eventtype>
<historyevent>Task moved</historyevent>
<details>From 'Requested' to 'In Validation'</details>
<author>NAme</author>
<entrydate>01 Jul 13, 11:34</entrydate>
<historyid>2620</historyid>
</taskEvent>
<taskEvent>
<eventtype>Updates</eventtype>
<historyevent>Subtask marked done</historyevent>
<details>Subtask: visualise status and versions</details>
<author>NAme2</author>
<entrydate>21 Jun 13, 10:16</entrydate>
<historyid>2588</historyid>
</taskEvent>
</historydetails>
analogicznym klas wyglądać następująco:
public class historydetails
{
[XmlElement("taskEvent")]
List<taskEvent> eventList = new List<taskEvent>();
}
public class taskEvent
{
string eventtype { get; set; }
string historyevent { get; set; }
string details { get; set; }
string author { get; set; }
string entrydate { get; set; }
string historyid { get; set; }
}
kod do deserialise xml (wymiana ciąg zawiera kod XML):
XmlSerializer deserializer = new XmlSerializer(typeof(historydetails));
object obj = obj = deserializer.Deserialize(stringToStream(replacement));
historydetails XmlData = (historydetails)obj;
metoda stringToStream
private MemoryStream stringToStream(string input)
{
byte[] byteArray = Encoding.ASCII.GetBytes(input);
MemoryStream stream = new MemoryStream(byteArray);
return stream;
}
Wynik, który otrzymuję, jest następujący: Obiekt XmlData został utworzony i znajduje się lista eventEvents. Problem jest w samym liście: jest pusty ...
Czy próbowali wypełniania obiektowi siebie i szeregowania go do XML do porównania? Jeśli jest to problem z hierarchią twoich elementów, zauważysz natychmiast. –
Pytania, w których "to nie działa" są prawie niemożliwe do odpowiedzi, chyba że spróbujesz {/ * nie powiodło się * /} catch (Exception ex) {ex.ToString(); } 'i dodaj wynik' ToString' do twojego pytania. – Will
Czy on nie dostanie błędu. Otrzymuje prawidłowy obiekt XML, ale jest pusty. – BlargleMonster