Serializing xml to object while keeping the original xml?

reneedove

New Member
I'm using an external API to receive xml and serializing this to an object but I want a way to be able to keep the original xml used to serialize for debugging and auditing.Here's a sample of how I'm serializing:\[code\]XmlReader reader = this.Execute(url);return Read<Property>(reader, "property");\[/code\]Extract of Execute() routine:\[code\]StringBuilder sb = new StringBuilder();Stream s = response.GetResponseStream();XmlReader reader = XmlReader.Create(s);return reader;\[/code\]Read() simply wraps up the native xml serialization:\[code\]private T Read<T>(XmlReader reader, string rootElement){ XmlRootAttribute root = new XmlRootAttribute(); root.ElementName = rootElement; root.IsNullable = true; XmlSerializer xmlSerializer = new XmlSerializer(typeof(T), root); object result = xmlSerializer.Deserialize(reader); return (T)result;}\[/code\]I've had a look around at it appears once you've used the reader, you can't use it again (forward only reading stream?). Without trying to change to much, how can I extract the contents of the reader as xml while still benefiting from the built in serialization with the reader?What would be nice is to adjust Read with an out param:\[code\]private T Read<T>(XmlReader reader, string rootElement, out string sourceXml);\[/code\]
 
Back
Top