What will happen to stream when XmlDocument is changed?

  • Thread starter Thread starter Peter Rilling
  • Start date Start date
P

Peter Rilling

I was I to load an Image or XmlDocument based on the data in the Stream, if
changes are made to the created object, will the stream be affected? In
other words, if new nodes are added to an XmlDocument after being loaded,
will the stream reflect those changes?
 
As long as you save it back, yes. It's difficult to figure out what you mean
by "stream" though. Are you talking about a DOM?
 
Peter Rilling said:
I was I to load an Image or XmlDocument based on the data in the Stream, if
changes are made to the created object, will the stream be affected? In
other words, if new nodes are added to an XmlDocument after being loaded,
will the stream reflect those changes?

No, the actual stream won't change at all. You can choose to save it
back to the original source of the stream, of course (if you've loaded
it from somewhere you can also write to) but you don't have to.
 
No, I mean a Stream object. For instance.

MemoryStream stream = new MemoryStream();
// Add some XML content to stream.
XmlDocument xml = new XmlDocument();
xml.Load(stream);
// Make some changes to the DOM. Is the stream updated immediatly?

Will those changes be reflected immediatly in the original stream? From
your reply, I would the the stream is not updated until a physical save is
invoked.
 
Peter Rilling said:
No, I mean a Stream object. For instance.

MemoryStream stream = new MemoryStream();
// Add some XML content to stream.
XmlDocument xml = new XmlDocument();
xml.Load(stream);
// Make some changes to the DOM. Is the stream updated immediatly?

Will those changes be reflected immediatly in the original stream? From
your reply, I would the the stream is not updated until a physical save is
invoked.

Oh, I see. No. It works the same way as if you'd loaded it from disk - the
stream is the backing store. You need to explicitly save it back if you want
it to be updated.
 
Back
Top