XmlDocument - How to create and use xml node in asp.net

XmlDocument XmlNode - How to create and use xml node in asp.net xml
XmlDocumentCraeteXmlNode.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ 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">
    void Button1_Click(object sender, System.EventArgs  e)
    {
        string xmlFilePath = Request.PhysicalApplicationPath + @"App_Data\SharePointBooks.xml";
        if (System.IO.File.Exists(xmlFilePath))
        {
            Label1.Text = "Already exists SharePointBooks.xml.";
        }
        else
        {
            XmlDocument xmlDoc = new XmlDocument();
            
            XmlDeclaration xmlDeclarationNode = xmlDoc.CreateXmlDeclaration("1.0","","");
            xmlDoc.AppendChild(xmlDeclarationNode);
            
            XmlNode booksNode = xmlDoc.CreateElement("books");
            xmlDoc.AppendChild(booksNode);
            
            XmlNode bookNode = xmlDoc.CreateElement("book");
            
            XmlNode bookidNode = xmlDoc.CreateElement("bookid");
            bookidNode.InnerText = "001";
            bookNode.AppendChild(bookidNode);
            
            XmlNode booktitleNode = xmlDoc.CreateElement("booktitle");
            booktitleNode.InnerText = "Professional Microsoft SharePoint 2007 Workflow Programming";
            bookNode.AppendChild(booktitleNode);
            
            booksNode.AppendChild(bookNode);
            xmlDoc.Save(xmlFilePath);
            Label1.Text = "SharePointBooks.xml created successfully!";
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XmlDocument XmlNode - How to create and use xml node in asp.net xml</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Olive; font-style:italic;">XmlDocument Example: How to create and use XmlNode</h2>
        <hr width="575" align="left" color="OliveDrab" />
        <br /><br />
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            Text=""
            ForeColor="OrangeRed"
            Font-Names="Comic Sans MS"
            Font-Size="X-Large"
            >
        </asp:Label>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Create XmlDocument Using XmlDocument"
            Height="40"
            Font-Bold="true"
            ForeColor="Olive"
            />
    </div>
    </form>
</body>
</html>








Related asp.net example