473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating an XML file in temporary memory

Hi,

I have a requirement where I need to create an xml file in temporary
memory and not on hard disk.

currently this is how I am creating an xml file using XmlTextWriter :
XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml",
null);

I do not want my xml file to be stored in C:/, I want it to be in
temporary memory,

Could anyone please assist me?

---
Bharathi

Jun 28 '07 #1
9 14187
Must it be a file? Perhaps use a MemoryStream - attach the writer to
this stream using the ctor. Later, simpy rewind the stream and Read()
it. Alternatively, if you just want the xml, consider using a
StringBuilder as the target - then just call ToString().

Marc
Jun 28 '07 #2
Hi

In temporory memory there is nothing so called "FILE". Temporory
memory is just a logical address space. As suggested by Marc, I think
using Memory strams will do in this case.
Thanks
-Cnu

On Jun 28, 11:58 am, Bharathi Harshavardhan <bharathi8...@gmail.com>
wrote:
Hi,

I have a requirement where I need to create an xml file in temporary
memory and not on hard disk.

currently this is how I am creating an xml file using XmlTextWriter :
XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml",
null);

I do not want my xml file to be stored in C:/, I want it to be in
temporary memory,

Could anyone please assist me?

---
Bharathi

Jun 28 '07 #3
On Jun 28, 7:58 am, Bharathi Harshavardhan <bharathi8...@gmail.com>
wrote:
I have a requirement where I need to create an xml file in temporary
memory and not on hard disk.

currently this is how I am creating an xml file using XmlTextWriter :
XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml",
null);

I do not want my xml file to be stored in C:/, I want it to be in
temporary memory,

Could anyone please assist me?
Others have suggested MemoryStream, and that's a fine idea if you want
the binary data. If you want the data as text, a StringWriter is
probably slightly easier.

Jon

Jun 28 '07 #4
On Thu, 28 Jun 2007 00:03:45 -0700, Marc Gravell <ma**********@gmail.com>
wrote:
Must it be a file? Perhaps use a MemoryStream - attach the writer to
this stream using the ctor. Later, simpy rewind the stream and Read()
it. Alternatively, if you just want the xml, consider using a
StringBuilder as the target - then just call ToString().
In addition to Marc's fine suggestion, you might also consider a
StringWriter, which wraps up a StringBuilder in a TextWriter, which you
can then use to construct your XmlTextWriter instance. Maybe this is what
he means by "consider using a StringBuilder as the target", since I don't
see any direct way to actually do that (that is, I don't see anything in
XmlTextWriter that takes a StringBuilder as a direct target).

The main advantage to using the StringWriter is that you have easier
access to the resulting XML text. If that's not of concern to you, then
the MemoryStream should work just fine.

Pete
Jun 28 '07 #5
On Thu, 28 Jun 2007 00:38:21 -0700, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote:
Others have suggested MemoryStream, and that's a fine idea if you want
the binary data. If you want the data as text, a StringWriter is
probably slightly easier.
Okay, I'll give you that one. You beat me by 7 seconds.

But only because I had to go back and check to see if I could figure out
what Marc meant by "using a StringBuilder as the target". :P
Jun 28 '07 #6
explained above
Jun 28 '07 #7
By which I meant:

StringBuilder sb = new StringBuilder();
using(XmlWriter writer = XmlWriter.Create(sb)) {
// write some xml
writer.Close();
}
string xml = sb.ToString();

Marc
Jun 28 '07 #8
Hi all,

Thank you all for the suggestions provided.

My problem got resolved :-)

I modified my code as below:

private string CreateXML()
{

StringBuilder sb = new StringBuilder();
XmlWriter xmlWriter = XmlWriter.Create(sb);
// Write xml
xmlWriter.Close();
return sb.ToString();
}

Thank you,
Regards,
Bharathi.

On Jun 28, 12:58 pm, "Marc Gravell" <marc.grav...@gmail.comwrote:
By which I meant:

StringBuilder sb = new StringBuilder();
using(XmlWriter writer = XmlWriter.Create(sb)) {
// write some xml
writer.Close();}

string xml = sb.ToString();

Marc

Jun 28 '07 #9
On Thu, 28 Jun 2007 00:58:59 -0700, Marc Gravell <ma**********@gmail.com
wrote:
By which I meant:

StringBuilder sb = new StringBuilder();
using(XmlWriter writer = XmlWriter.Create(sb)) [...]
I see. I'll point out that the OP wasn't using an XmlWriter, so IMHO your
reply would have be more clear if you'd made clear you also intended for
him to change the class he was using to write the XML.

Pete
Jun 28 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Joerg Schuster | last post by:
Hello, I am looking for a method to "shuffle" the lines of a large file. I have a corpus of sorted and "uniqed" English sentences that has been produced with (1): (1) sort corpus | uniq >...
4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
9
by: cppaddict | last post by:
I have a method that uses a fairly large object. The choice is between having a local object in the method or a static member object that the method uses. ------CHOICE 1--------- int...
6
by: Dan | last post by:
Maybe the title is a little misleading, but I don't know a better way of putting it. What I would like to do, is create a file pointer that really isn't pointing to an actual file on disk, but a...
11
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
5
by: barnetod | last post by:
I am trying to open a text file designated by the user. Then I want to change all lower case values to capital letters. Then write file. I am stuck and can not change the characters or am...
3
by: tshad | last post by:
oThumbnail.Save is giving me an error: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. theFileName = New FileInfo(strFileName) fileOut =...
10
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.