Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Xml Text Writer
WhatsApp
Rajendra Tripathy
10y
23.3
k
0
0
25
Blog
XmlTextWriter Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files containing XML data. XmlTextWriter renders XML data to a string. This string remains in the memory of the C# program. XmlTextWriter is useful for in-memory generation of XML.
private
void
button1_Click(
object
sender, EventArgs e)
{
// Creates an instance of the System.Xml.XmlTextWriter class using the specified file.
XmlTextWriter textWriter =
new
XmlTextWriter(@
"C:\xmlfile.xml"
,
null
);
// Writes the XML declaration with the version "1.0".
textWriter.WriteStartDocument();
// Write comments
textWriter.WriteComment(
"First Comment for XmlTextWriter Sample Example"
);
// Write first element
textWriter.WriteStartElement(
"Student"
);
textWriter.WriteStartElement(
"Document"
,
"Test"
,
"RECORD"
);
// Write next element Name
textWriter.WriteStartElement(
"Name"
);
textWriter.WriteString(
"Rajendra"
);
textWriter.WriteEndElement();
// Write element Address
textWriter.WriteStartElement(
"Address"
);
textWriter.WriteString(
"Bangalore"
);
textWriter.WriteEndElement();
// Write element Pincode
textWriter.WriteStartElement(
"Pincode"
);
textWriter.WriteString(
"560066"
);
textWriter.WriteEndElement();
// WriteChars
char
[] ch =
new
char
[3];
ch[0] =
'R'
;
ch[1] =
'A'
;
ch[2] =
'J'
;
textWriter.WriteStartElement(
"Char"
);
textWriter.WriteChars(ch, 0, ch.Length);
textWriter.WriteEndElement();
// Ends the document.
textWriter.WriteEndDocument();
// close writer
textWriter.Close();
}
Result
Xml Text Writer
Up Next
Binding XML File with GridView in .net
Ebook Download
View all
.NET Interview Questions and Answer: Practical Implementation
Read by 41.8k people
Download Now!
Learn
View all
Membership not found