LINQ to XML - How to create an XML declaration for a document - Using XDocument XDeclaration
CreateXMLDeclaration.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Xml.Linq" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
XDocument myDoc = new XDocument
(
new XDeclaration("1.0","utf-8","yes"),
new XElement("Root","root contents")
);
Literal1.Text = myDoc.Declaration.ToString();
Literal2.Text = myDoc.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>LINQ to XML - How to create an XML declaration for a document - Using XDocument XDeclaration</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
LINQ to XML - How to create an XML declaration for a document
<br />Using XDocument XDeclaration
</h2>
<hr width="600" align="left" color="CornFlowerBlue" />
<asp:Literal
ID="Literal1"
runat="server"
Mode="Encode"
>
</asp:Literal>
<br />
<asp:Literal
ID="Literal2"
runat="server"
Mode="Encode"
>
</asp:Literal>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Create an XML declaration"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>

- linq - Get a subset of elements from a sequence that match condition
- linq - How to generate a list with a specific range of numbers
- linq - How to repeat an item to generate a sequence
- linq - How to determine whether two sequences are equal
- linq - How to get difference between two sequences
- linq - How to filter elements of a sequence by data type
- How to convert Linq query result to an array
- c# - How to convert Linq query result to a List
- linq - How to union two sequences
- linq - How to get the average value from a numeric sequence