[quoted text, click to view] "Raterus" <raterus@hotmail.com> wrote in message news:%238C0OAfGFHA.3072@tk2msftngp13.phx.gbl...
> What is the best way to take the results from the XmlSerializer and convert it into
> an XmlDocument.
: :
> Can someone point me in the right direction as to the best way to do this?
Create an empty XmlDocument, like this
XmlDocument doc = new XmlDocument( );
then use Chris Lovett's XmlNodeWriter [1] to wrap the XmlDocument and
pipe the serialization calls to it through Serialize( )'s XmlWriter argument,
serializer.Serialize( obj, new XmlNodeWriter( doc) );
[quoted text, click to view] > I can serialize the class to a file, then load the file, but that is like going
> around my elbow to get to my thumb!, there has to be a better way!
If you don't like using the XmlNodeWriter then alternatively, you can
dispatch with the File altogether and serialize to a String or Memory-
Stream (take your choice; everybody has their favorite) and wrap
that in a StringWriter / StreamWriter to pipe the results through the
Serialize( )'s TextWriter argument.
Then use doc.LoadXml( ) or re-set the Position of your Memory-
Stream to 0 and then use doc.Load( new StreamReader( ms) ) on
it.
Dispatching with the File makes this more like going around your
wrist to get to your thumb.
XmlNodeWriter should be present in the System.Xml namespace of
..NET 2.0 (present as of Beta 1; can't imagine it'd get pulled though),
so if your application targets 2.0 it'll simplify matters greatly for you.
Derek Harmon
___
[1] - Chris Lovett's XmlNodeWriter on GotDotNet
http://www.gotdotnet.com/community/usersamples/Default.aspx?query=XmlNodeWriter