473,403 Members | 2,354 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,403 software developers and data experts.

Creating XML Text

Hello,

I need to create some well formed XML text live in memory. What I really
want is to use the XmlTextWriter object applied to some location in memory
(Stream or something?), because it does a nice job of formatting/identing,
etc. But I can't figure out how to instantiate the XmlTextWriter object
correctly w/o a filespec. I'm not allowed to directly instantiate a Stream &
therefore a StreamWriter for that matter since there's no filespec involved.
Can someone show me some code to make this work?

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com
Nov 12 '05 #1
2 3067


John Bowman < wrote:

I need to create some well formed XML text live in memory. What I really
want is to use the XmlTextWriter object applied to some location in memory
(Stream or something?), because it does a nice job of formatting/identing,
etc. But I can't figure out how to instantiate the XmlTextWriter object
correctly w/o a filespec. I'm not allowed to directly instantiate a Stream &
therefore a StreamWriter for that matter since there's no filespec involved.
Can someone show me some code to make this work?


You could use a StringWriter as a TextWriter to create the XmlTextWriter on:

StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteStartElement("god");
xmlWriter.WriteAttributeString("name", "Kibo");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.Flush();
xmlWriter.Close();
Console.WriteLine(stringWriter.ToString());
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Martin,

Thanks! That works great.

John

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...


John Bowman < wrote:

I need to create some well formed XML text live in memory. What I really
want is to use the XmlTextWriter object applied to some location in
memory (Stream or something?), because it does a nice job of
formatting/identing, etc. But I can't figure out how to instantiate the
XmlTextWriter object correctly w/o a filespec. I'm not allowed to
directly instantiate a Stream & therefore a StreamWriter for that matter
since there's no filespec involved. Can someone show me some code to make
this work?


You could use a StringWriter as a TextWriter to create the XmlTextWriter
on:

StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteStartElement("god");
xmlWriter.WriteAttributeString("name", "Kibo");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.Flush();
xmlWriter.Close();
Console.WriteLine(stringWriter.ToString());
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

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

Similar topics

6
by: owen | last post by:
Generally speaking, what does it mean when I see a "button" with red text showing this message instead of the control I've dragged onto the web form in Design View.? (But the page works fine at...
4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
1
by: Boris | last post by:
All, Please help me with following error. I am using classic ASP to connect to MS Access DB to create a table dynamically. Following is the table definition. I get the error when I execute the...
9
by: Sheldon Cohen | last post by:
Hello, I am using c# and running a site that is on a shared host. The code in question is supposed to create a new directory that is coming out of a text box. It works fine on my computer, but...
4
by: Coleen | last post by:
Hi All :-) Can anyone give me a URL where I can find a good example of code on how to create a temporary SQL table using VB.net? I've checked the Microsoft site at: ...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
3
by: simon | last post by:
Hello, i'm looking to create an aspx page that is basically a FAQ page i'm not sure if this can be done, but would love some help with suggestions of how to do it another way if this is not...
5
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function...
7
by: Burden | last post by:
Please help i am hitting my head against a wall here. I am creating a database to use with a touchscreen and i have created a pop up keyboard. I have got stuck on two things. Firstly when i am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.