I have an existing application which manipulates data as an XML DOM model. I now want to hand that data off to another subsystem as a collection of C# objects.
As far as I can tell, I could serialise the DOM representation to a MemoryStream and the deserialise the stream using an XmlSerializer. Surely there is a way of processing the DOM representation directly, without the intervening textual representation? But I can’t find it.
How can I use System.Xml.Serialization on a DOM representation?
It sounds like you want to project an XmlDocument into a custom collection. You can do this with XmlSerializer.Deserialize but it requires that your XmlDocument have its structure lined up nicely with the collection members.
If this is true then using
XmlSerializer.Deserialize Methodis a perfectly fine approach using anXmlNodeReader.e .g.
However if you find that the XmlDocument doesn’t line up with your collection you might just want to use Linq-to-xml and do what ever projection you like.