Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Literal ID="Literal1" runat="server" Mode="Encode"></asp:Literal></div>
    </form>
</body>
</html>

Default.aspx.cs :

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<deneme/>");
        #region just to remind myself something
        XmlNode node = doc.CreateElement("serkan");
        doc.DocumentElement.AppendChild(node);
        #endregion
        StringWriter sw = new StringWriter();
        XmlTextWriter tx = new XmlTextWriter(sw);
        doc.WriteTo(tx);
        // i use literal control because when you set its mode to "encode", you can write xml tags to browser window as they are
        Literal1.Text = sw.ToString();
        
        
    }
}
3
Contributors
2
Replies
30
Views
8 Years
Discussion Span
Last Post by evancroby
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.