XmlDocument AppendChild() - How to use AppendChild() method in asp.net
XmlDocumentAppendChild.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html>
<script runat="server">
void Button1_Click(object sender, System.EventArgs e)
{
string xmlFilePath = Request.PhysicalApplicationPath + @"App_Data\EmployeeList.xml";
if (System.IO.File.Exists(xmlFilePath))
{
Label1.Text = "EmployeeList.xml already exists.";
}
else
{
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmlDeclarationNode = xmlDoc.CreateXmlDeclaration("1.0","","");
xmlDoc.AppendChild(xmlDeclarationNode);
XmlNode employeesNode = xmlDoc.CreateElement("employees");
xmlDoc.AppendChild(employeesNode);
XmlNode employeeNode = xmlDoc.CreateElement("employee");
XmlNode employeeNameNode = xmlDoc.CreateElement("employeename");
employeeNameNode.InnerText = "Jenny Jones";
employeeNode.AppendChild(employeeNameNode);
XmlNode cityNode = xmlDoc.CreateElement("city");
cityNode.InnerText = "Rome";
employeeNode.AppendChild(cityNode);
employeesNode.AppendChild(employeeNode);
xmlDoc.Save(xmlFilePath);
Label1.Text = "EmployeeList.xml created successfully!";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>XmlDocument AppendChild() - How to use AppendChild() method in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Magenta; font-style:italic;">XmlDocument Example: How to use AppendChild() method</h2>
<hr width="575" align="left" color="Pink" />
<br /><br />
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
Text=""
ForeColor="SeaGreen"
Font-Names="Comic Sans MS"
Font-Size="X-Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Create EmployeeList.xml XmlDocument Using XmlDocument"
Height="40"
Font-Bold="true"
ForeColor="IndianRed"
/>
</div>
</form>
</body>
</html>



- asp.net and XPath: evaluate | (union of the results of two paths) XPath expression
- asp.net and XPath: evaluate [] (selection criteria) XPath expression
- asp.net and XPath: evaluate position XPath expression
- asp.net and XPath: evaluate [position()<5] XPath expression
- asp.net and XPath: evaluate [position()>4] XPath expression
- XmlDocument XmlNode - How to create and use xml node in asp.net xml
- XmlDocument CreateComment() - How to create comment in asp.net xml document
- XmlDocument PrependChild() - How to use PrependChild() method in asp.net