Subject: How to deserialize the iq object sent over XMPP back to my own type ?
Hi Alex,
now I can send my own type via XMPP in a iq object.
My next challenge is to deserialize the e.iq to my own object type.
1. Question - Why is xdoc == null true using the following: XDocument xdoc = e.Iq.Document
Details:
void xmppClient_OnIq(object sender, IqEventArgs e)
{
...
if (e.Iq.Type == Matrix.Xmpp.IqType.get)
{
...
WriteToChatReceive(e.Iq.ToString()); // prints out the whole xml tree as I would expect
XDocument xdoc = e.Iq.Document; // xdoc gets the XDocument from e.Iq or not ?
MessageBox.Show((xdoc == null).ToString()); // should result in "False" but result is "True" !!??
...
}
...
}
2. Question
Is there a more automatic / generic / elegant way to deserialize the xml content of e.iq to my own type ?
I currently use the following:
var query = from xElem in xdoc.Descendants("Person")
select new Person
{
Vorname = xElem.Element("Vorname").Value,
Nachname = xElem.Element("Nachname").Value,
Alter = Int16.Parse(xElem.Element("Alter").Value),
....
};
It doesn't work till now cause my problem with xdoc = e.Iq.Document of question 1 I asked above,
but I hope it will work after solving question 1.
Thanks for your help.
Martin
now I can send my own type via XMPP in a iq object.
My next challenge is to deserialize the e.iq to my own object type.
1. Question - Why is xdoc == null true using the following: XDocument xdoc = e.Iq.Document
Details:
void xmppClient_OnIq(object sender, IqEventArgs e)
{
...
if (e.Iq.Type == Matrix.Xmpp.IqType.get)
{
...
WriteToChatReceive(e.Iq.ToString()); // prints out the whole xml tree as I would expect
XDocument xdoc = e.Iq.Document; // xdoc gets the XDocument from e.Iq or not ?
MessageBox.Show((xdoc == null).ToString()); // should result in "False" but result is "True" !!??
...
}
...
}
2. Question
Is there a more automatic / generic / elegant way to deserialize the xml content of e.iq to my own type ?
I currently use the following:
var query = from xElem in xdoc.Descendants("Person")
select new Person
{
Vorname = xElem.Element("Vorname").Value,
Nachname = xElem.Element("Nachname").Value,
Alter = Int16.Parse(xElem.Element("Alter").Value),
....
};
It doesn't work till now cause my problem with xdoc = e.Iq.Document of question 1 I asked above,
but I hope it will work after solving question 1.
Thanks for your help.
Martin