how to write the values in textbox to xml format..
-
Hi, Am working in Asp.net using C#.I have 4 textboxes and 1 button in my application.After the user enters values in 4 textboxes he will click the button.On button click the values in textbox should be written in XML format....Usually to insert values in database we will use INSERT query..But instead of saving in Database i should write the values in textbox directly to XML. S it possible to write the values in Textbox directly to xml??? Can u help me in doing this....Thanx in advance..
Regards, Samson
-
Hi, Am working in Asp.net using C#.I have 4 textboxes and 1 button in my application.After the user enters values in 4 textboxes he will click the button.On button click the values in textbox should be written in XML format....Usually to insert values in database we will use INSERT query..But instead of saving in Database i should write the values in textbox directly to XML. S it possible to write the values in Textbox directly to xml??? Can u help me in doing this....Thanx in advance..
Regards, Samson
Yes, that is possible. Try this little horrorcode;
string asXML = @"<codinghorrorxml>" + Environment.NewLine;
asXML += @"<textbox1>" + textBox1.Text + @"</textbox1>" + Environment.NewLine;
asXML += @"<textbox2>" + textBox2.Text + @"</textbox2>" + Environment.NewLine;
asXML += @"<textbox3>" + textBox3.Text + @"</textbox3>" + Environment.NewLine;
asXML += @"</codinghorrorxml>";You'll also need to write this string to disk, I presume. There's a StreamWriter somewhere in System.IO.
I are troll :)
-
Yes, that is possible. Try this little horrorcode;
string asXML = @"<codinghorrorxml>" + Environment.NewLine;
asXML += @"<textbox1>" + textBox1.Text + @"</textbox1>" + Environment.NewLine;
asXML += @"<textbox2>" + textBox2.Text + @"</textbox2>" + Environment.NewLine;
asXML += @"<textbox3>" + textBox3.Text + @"</textbox3>" + Environment.NewLine;
asXML += @"</codinghorrorxml>";You'll also need to write this string to disk, I presume. There's a StreamWriter somewhere in System.IO.
I are troll :)
-
hi, I don know how to use streamwriter and save the xml... Please give me some idea over there... Thanks in advance
Regards, Samson
-
Hi, I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it string asXML = @"" + Environment.NewLine; asXML += @"" + txtid.Text + @"" + Environment.NewLine; asXML += @"" + txtname.Text + @"" + Environment.NewLine; asXML += @"" + txtage.Text + @"" + Environment.NewLine; asXML += @""; FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(test); sw.Write("Hello file system world!"); sw.Close(); test.Close(); It's not creating the test.xml file... Please correct it... Thanks in advance
Regards, Samson
-
Hi, I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it string asXML = @"" + Environment.NewLine; asXML += @"" + txtid.Text + @"" + Environment.NewLine; asXML += @"" + txtname.Text + @"" + Environment.NewLine; asXML += @"" + txtage.Text + @"" + Environment.NewLine; asXML += @""; FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(test); sw.Write("Hello file system world!"); sw.Close(); test.Close(); It's not creating the test.xml file... Please correct it... Thanks in advance
Regards, Samson
Here i had change the code as sw.write(asXML); i got the xml file,but it's not writing the value from textbox. I'm Getting the folloeing error. XML document must have a top level element. Error processing resource 'file:///C:/Documents and Settings/sbritto/Desktop/test.xml Please correct it... Thanks in advance
With Regards, Samson
-
Hi, I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it string asXML = @"" + Environment.NewLine; asXML += @"" + txtid.Text + @"" + Environment.NewLine; asXML += @"" + txtname.Text + @"" + Environment.NewLine; asXML += @"" + txtage.Text + @"" + Environment.NewLine; asXML += @""; FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(test); sw.Write("Hello file system world!"); sw.Close(); test.Close(); It's not creating the test.xml file... Please correct it... Thanks in advance
Regards, Samson
samsonx wrote:
Please correct it...
Well, I'd recommend you do some reading on XML, and possibly C#. You either are hoping for some sort of magic to happen that has nothing to do with any code that you've written, or you plain have no idea. You've not written any nodes here, this would only work if you magically happened to type the right values into your textboxes to create XML. Either way, as the original guy said, this is horrible code. XmlTextWriter is the class you should be using. I've confirmed that there's tons of info and examples on the web, easily found with your search engine of choice.
Christian Graus Driven to the arms of OSX by Vista.
-
Here i had change the code as sw.write(asXML); i got the xml file,but it's not writing the value from textbox. I'm Getting the folloeing error. XML document must have a top level element. Error processing resource 'file:///C:/Documents and Settings/sbritto/Desktop/test.xml Please correct it... Thanks in advance
With Regards, Samson
you're not writing XML. Stop flailing about in the dark, abandon the path of ignorance, and actually do some work to establish that the code you enter stands some semblance of a chance of working.
Christian Graus Driven to the arms of OSX by Vista.
-
samsonx wrote:
Please correct it...
Well, I'd recommend you do some reading on XML, and possibly C#. You either are hoping for some sort of magic to happen that has nothing to do with any code that you've written, or you plain have no idea. You've not written any nodes here, this would only work if you magically happened to type the right values into your textboxes to create XML. Either way, as the original guy said, this is horrible code. XmlTextWriter is the class you should be using. I've confirmed that there's tons of info and examples on the web, easily found with your search engine of choice.
Christian Graus Driven to the arms of OSX by Vista.