protected void Page_Load( object sender, EventArgs e)
{
string xmlPath = Server.MapPath( " ~/Employee.xml " );
XmlWriterSettings setting
= new XmlWriterSettings();
setting.Indent
= true ;
setting.IndentChars
= " \t " ;
using (XmlWriter writer = XmlWriter.Create(xmlPath,setting))
{
writer.WriteStartDocument(
false );
writer.WriteComment(
" This XML file represents the details of an employee " );
writer.WriteStartElement(
" employees " );
writer.WriteStartElement(
" employee " );
writer.WriteAttributeString(
" id " , " 1 " );
writer.WriteStartElement(
" name " );
writer.WriteElementString(
" firstName " , " Nancy " );
writer.WriteElementString(
" lastName " , " lastName " );
writer.WriteEndElement();
writer.WriteElementString(
" city " , " Seattle " );
writer.WriteElementString(
" state " , " WA " );
writer.WriteElementString(
" zipCode " , " 98122 " );
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
lblResult.Text
= " File is written successfully! " ;
}

}

posted on 2009-07-27 09:22  vibratea  阅读(241)  评论(0编辑  收藏  举报