How to write attribute in xml file in asp.net

WriteAttributeString() Method - Write attribute in XML file
WriteAttribute.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        string xmlFile = Request.PhysicalApplicationPath + @"App_Data\BookStore2.xml";
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        settings.ConformanceLevel = ConformanceLevel.Auto;
        settings.OmitXmlDeclaration = false;
        try
        {
            using (XmlWriter writer = XmlWriter.Create(xmlFile, settings))
            {
                writer.WriteStartDocument(false);
                writer.WriteComment("Sample file for test WriteAttributeString method.");
                writer.WriteStartElement("books");
                writer.WriteStartElement("book");
                writer.WriteAttributeString("id", "001"); ;
                writer.WriteElementString("name", "Learn Adobe Photoshop CS4 by Video");
                writer.WriteElementString("author", "Video2Brain");
                writer.WriteElementString("price","$59.99");
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.Flush();
                Label1.Text = "File written successfully!";
                }
            }
        catch (Exception ex)
        {
            Label1.Text = "An Error Occured: " + ex.Message;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>WriteAttributeString: How to write attribute in xml file in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">XML Example: Writing Attributes In Xml File</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="false"
             ForeColor="HotPink"
             Font-Size="Large"
             Font-Names="Comic Sans MS"
             >
        </asp:Label>
    </div>
    </form>
</body>
</html>
Related asp.net example