Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

Filestream, Stream, StreamReader

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jacques van der Hoven - 27 Jul 2005 14:29 GMT
My situation is simple:
I have an Xml doc that I want to transform into another Xml doc.
I've tested the Xslt in an Xml editor and it works perfectly.
So in C# I create an Xml Document object and load the source xml. Then I
create the XslTransform object and load the xslt. I create a second Xml
document object to store the results of the transform.
There is no need at this stage to write the xml to disk.
The call I'm making to Transform is the one that requires a Stream object as
a parameter.
Here's a small section of the code:
XslTransform transformDoc = new XslTransform();
transformDoc.Load(transformDocumentsPath + xsltFile);

//if the file loaded successfully
if (transformDoc != null){
    XmlDocument currentXml = new XmlDocument();
    currentXml.Load(document);  //document refers to another stream of data
uploaded via a website
   
    if (currentXml != null && currentXml.ChildNodes.Count > 0){
         XmlDocument resultXml = new XmlDocument();
         FileStream stream = null;
         
transformDoc.Transform(currentXml.CreateNavigator(),null,stream,null);
         resultXml.Load(stream);
         return resultXml; }

My problem is with my understanding of how Streams work.

When I run this code I get an error saying that the Stream cannot be null,
which I understand. What I'm not getting though is that streams are for
reading and writing, does this just mean from files written to disk? Or could
I use a stream the way I attempting do it right now?

Thanks
Jacques
Joerg Jooss - 31 Jul 2005 07:31 GMT
> My situation is simple:
> I have an Xml doc that I want to transform into another Xml doc.
[quoted text clipped - 5 lines]
> The call I'm making to Transform is the one that requires a Stream
> object as a parameter.
[...]
> My problem is with my understanding of how Streams work.
>
> When I run this code I get an error saying that the Stream cannot be
> null, which I understand. What I'm not getting though is that streams
> are for reading and writing, does this just mean from files written
> to disk? Or could I use a stream the way I attempting do it right now?

Jacques,

there are different types of streams -- FileStrams, NetworkStreams,
MemoryStreams. If you don't need to persist your XSLT result at this
point in time, use a MemoryStream to dump the transformation result to
memory. From here, you can construct another XmlDocument, either using
XmlDocument.Load() or an XmlReader that wraps the MemoryStream.

Cheers,
Signature

http://www.joergjooss.de
mailto:news-reply@joergjooss.de


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.