473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

write XML

I'm trying to write XML and I am quite unsuccessful so far,
I have a very simple application with 1 button and one click handler like
that, does anyone know what's wrong with this few lines ?
//-----------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
string file = "test.xml";
XmlTextWriter xtw = new XmlTextWriter(file, Encoding.UTF8);
try
{
xtw.WriteStartDocument();
xtw.WriteElementString("Name", "aName");
xtw.WriteStartElement("Data");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteEndElement();
xtw.WriteEndDocument();
}
finally { xtw.Close(); }
}

it throws an InvalidOperationExeption() when I try to
WriteStartElement("Data");
Nov 15 '05 #1
1 1159
no worries, I found it !
I should have a first line setting the namespace ....

"Lloyd Dupont" <[bad.user=lloyd;good.user=ld]@[server=galador.net]> wrote in
message news:O6**************@tk2msftngp13.phx.gbl...
I'm trying to write XML and I am quite unsuccessful so far,
I have a very simple application with 1 button and one click handler like
that, does anyone know what's wrong with this few lines ?
//-----------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
string file = "test.xml";
XmlTextWriter xtw = new XmlTextWriter(file, Encoding.UTF8);
try
{
xtw.WriteStartDocument();
xtw.WriteElementString("Name", "aName");
xtw.WriteStartElement("Data");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteElementString("Item", "anItem");
xtw.WriteEndElement();
xtw.WriteEndDocument();
}
finally { xtw.Close(); }
}

it throws an InvalidOperationExeption() when I try to
WriteStartElement("Data");

Nov 15 '05 #2

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

Similar topics

10
2889
by: Greg Hurlman | last post by:
I've got what I'm sure is a very simple problem. In an ASP page, I am trying to write out 4 fields from a recordset in succession: Response.Write rs("LastName") Response.Write rs("Suffix")...
1
2857
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
2366
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
0
1739
by: hari krishna | last post by:
hi all, My requirement is to generate xl reports throu Asp.Net without installing xl on web server computer. i am using Response object and wrtifile method as below. i dont know whether it is...
8
17867
by: Ben | last post by:
Hi all, Just wondering how to write (using document.write) to a table cell. I have table with 3 rows and 3 colums. I want to write from within the Javascript to say third column of a first row....
4
2931
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
11
16194
by: Vmusic | last post by:
Hi, I am trying to write out an array of string variables to Notepad. I can't get SendKeys to accept the string variable only literal quoted strings. I DO NOT want the hassle of writing to a...
4
4314
by: cbtechlists | last post by:
I have an ASP app that we've moved from a Windows 2000 to a Windows 2003 server (sql server 2000 to sql server 2005). The job runs fine on the old servers. Part of the app takes a recordset and...
0
5863
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
8
7084
by: Mateusz Viste | last post by:
Hi, I am trying make some multimedia files playable from my website. So far, I am able to generate dynamically a new page containing the right <embed> section. However, when I load my script, it...
0
7265
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
7388
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
7539
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...
1
5095
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...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.