![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How to Deserialise an XML stream Polymorphically I am writing and reading XML on a TCP connection. Once I have sent an XML message I have to wait for a reply, which could be in one of several forms. All the possible replys have a basic set of attributes in common, but then might have additional information. I have a base class for the common attributes and derived classes for the variants. What I would like to do is deserialise the reply, polymorphically, to an object of the derived class but I'm not sure how to do that. I have tried deserialising as a generic reply in order to test what type of object I have, but the deserialise call fails with an error in the stream. I can understand why it fails, because there are attributes in the stream that do not exist in the base class, but that doesn't get me any closer to the solution. If I know what derived class the reply is I can explicitly deserialise as that object type, but in normal operation I don't know what object type I am receiveing until I have deserialised it, if that makes sense. Does anyone have an idea how this might be done? TIA Charles |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to Deserialise an XML stream Polymorphically Charles wrote: Quote: > If I know what derived class the reply is I can explicitly deserialise as > that object type, but in normal operation I don't know what object type I am > receiveing until I have deserialised it, if that makes sense. > > Does anyone have an idea how this might be done? (e.g. LocalName, NamespaceURI, attributes) to hopefully be able to tell what kind of derived type you are dealing with, then you can feed an XmlNodeReader over the XmlDocument (or its DocumentElement) to XmlSerializer. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to Deserialise an XML stream Polymorphically Hi Martin Thanks for the very quick reply. That sounds like just the sort of thing I was after. Out of interest, suppose I try to deserialise the network stream associated with my TCP connection before the full XML reply has come in, will I get an obvious error? Is there a standard way of ensuring that I have a complete XML message, or a proper way to detect that I haven't? Charles "Martin Honnen" <mahotrash@xxxxxx> wrote in message news:OhjX$3zoJHA.3876@xxxxxx Quote: > Charles wrote: > Quote: >> If I know what derived class the reply is I can explicitly deserialise as >> that object type, but in normal operation I don't know what object type I >> am receiveing until I have deserialised it, if that makes sense. >> >> Does anyone have an idea how this might be done? > Load into an XmlDocument first, then you can check the root element (e.g. > LocalName, NamespaceURI, attributes) to hopefully be able to tell what > kind of derived type you are dealing with, then you can feed an > XmlNodeReader over the XmlDocument (or its DocumentElement) to > XmlSerializer. > > > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to Deserialise an XML stream Polymorphically Charles wrote: Quote: > Out of interest, suppose I try to deserialise the network stream associated > with my TCP connection before the full XML reply has come in, will I get an > obvious error? Is there a standard way of ensuring that I have a complete > XML message, or a proper way to detect that I haven't? as defined in the XML specification, so you need to have a single root element containing all other elements, otherwise you will get an XmlException. So consuming the network stream directly with the Load method of an XmlDocument is probably not going to work if you don't know for sure the XML is complete, you will to buffer the data. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to Deserialise an XML stream Polymorphically That makes sense. Many thanks again. Charles "Martin Honnen" <mahotrash@xxxxxx> wrote in message news:%23$1lVG0oJHA.3876@xxxxxx Quote: > Charles wrote: > Quote: >> Out of interest, suppose I try to deserialise the network stream >> associated with my TCP connection before the full XML reply has come in, >> will I get an obvious error? Is there a standard way of ensuring that I >> have a complete XML message, or a proper way to detect that I haven't? > If you parse XML with XmlDocument then it expects a well-formed document > as defined in the XML specification, so you need to have a single root > element containing all other elements, otherwise you will get an > XmlException. > > So consuming the network stream directly with the Load method of an > XmlDocument is probably not going to work if you don't know for sure the > XML is complete, you will to buffer the data. > > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| WMV stream seeking? | .NET General | |||
| .wmv will not stream on wmp | Vista General | |||
| Stream Live TV | Vista General | |||
| How to stream video | Vista music pictures video | |||
| Stream recording | Vista General | |||