Re: XmlDocument.Load using MemoryStream...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



memyselfandI <memyselfandI@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Thanks, it worked. The problem was the myWriter.Flush() method. I had it
> in the wrong place!! I didn't fully understand what it did, I thought it was
> part of clean up. Needed to do that before the myStream.Seek() and
> myXmlDocument.Load() method calls. Silly me.
>
> While I have you though, could you tell me using the
> MemoryStream/XmlTextWriter combo to make my XmlDocument is preferable to just
> building the XmlDocument directly? Or is this just a "more than one way to
> skin a cat" kinda deal.

It's not, particularly - unless you're passing the "new" document to a
method which might modify it, and you want to keep hold of the
original.

Even if you *do* want to clone, you should look at calling
XmlDocument.CloneNode instead, as it's a lot easier than writing it all
out and reading it back in.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages