write a sample code make use of xmltext writer

Answer Posted / career.tina@yahoo.co.in

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
//creating a apth for writing xml
string xml1 = Server.MapPath("test2.xml");
//initialising xmlwriter
XmlTextWriter xt = new XmlTextWriter(xml1,
System.Text.Encoding.UTF8);
xt.Formatting = System.Xml.Formatting.Indented;
//start writing it
xt.WriteStartDocument();
//element
xt.WriteStartElement("name");
// attribute
xt.WriteAttributeString("my_name", "name");
xt.WriteStartElement("phn");
xt.WriteAttributeString("my_phn", "266549560");
xt.WriteStartElement("id");
xt.WriteAttributeString("my_id", "100");
xt.WriteStartElement("city");
xt.WriteAttributeString("my_city", "city");
xt.WriteElementString ("title","gud girl");
//ending all elements
xt.WriteEndElement ();
xt.WriteEndElement();
xt.WriteEndElement();
xt.WriteEndElement();
xt.WriteEndDocument();
xt.Close ();

}
catch
{
}

}
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain serialization and deserialization?

542


What is viewstate? In which event of the page life cycle, is the viewstate available?

605


What is the difference between session.abandon() vs clear()?

542


How can you ensure a permanent cookie?

549


Explain about Multi-Language integration?

599






What are uri parameters?

541


What is http only cookie?

499


Is redux flux?

534


Which is the best institute to learn Microsoft Technologies and the faculty if you Know?

1611


What symbol specifies the beginning of a query string?

531


What is simple data binding?

518


What is cookies cache and session?

541


Describe how passport authentication works.

566


What is the difference between CLICK and MOUSE DOWN Event ?

584


How can you handle errors in Web API?

593