Passing xml between components

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to pass info between two components using xml. To produce the xml
I'm using an xmltextwriter, and in the receiving end I use an xmldocument and
its Load method to load the output of the writer.

If I use an intermedary file I have no problem, but if I use a MemoryStream
(one of its purposes is to avoid the need for temporary files, right?) then I
get an error telling me that no root element was found. How could this be?!!
Does anyone have an example of using a stream to pass xml around?

While I'm in the subject, what would be the "correct" (or most appropriate)
way of passing the xml data between components? a string? a stream? an
xmlreader? an xmldocument?
 
I think what might be the problem.

If you write to the MemoryStream, and then want to read what you have
written from the beginning, then you will have to seek the MemoryStream back
to the beginning of stream.
So i think, one line of code might interest you(well, if it is not already
there..):
memoryStream.Seek(0x0, SeekOrigin.Begin);
 
Thanks for such a prompt reply Dennis; what you said made a lot of sense, so
I tried it out. It worked!! thank you so much!

Regarding my second question... after days trying I stumbled upon the
following article after I posted my question:
http://msdn.microsoft.com/library/en-us/dnexxml/html/xml03172004.asp (Extreme
XML column - Best Practices for Representing XML in the .NET Framework). It
seems to provide good tips, although it doesn't mention streams as another
possibility to pass xml around.

Cheers!
 
Hello PJChan,
While I'm in the subject, what would be the "correct" (or most
appropriate) way of passing the xml data between components? a string?
a stream? an xmlreader? an xmldocument?

I would suggest either XmlReader or IXPathNavigable. Both are abstractions,
so that you can vary the implementation without breaking the interface.
 
Back
Top