I want to display/output xml on the screen, but I can't. Each time I use something like Response.Write the XML tags don't appear on the screen. There isn't anything else on the page. On Page_Load I read a Session Variable that contains a string of XML data
and I want to be able to display it to the screen. Is there any way to display this as plain text?
Thanks, that worked. When I view the source the markup contains < and "
Is there a way to avoid this? Does it have anything to do with the way I am escaping my characters? I am just using the backslash "\". Is there a better technique? I know that by putting a "@" before your string
has something to do with escaping characters.
SuPeR-MaRiO
Member
50 Points
10 Posts
Outputting XML To The Screen
Aug 29, 2006 03:59 PM|LINK
sbyard
Contributor
5891 Points
1196 Posts
Re: Outputting XML To The Screen
Aug 29, 2006 07:26 PM|LINK
You can do the following
Response.Write(Server.HtmlEncode("<root><myData>123</myData><myData>"A string"</myData></root>"));
SuPeR-MaRiO
Member
50 Points
10 Posts
Re: Outputting XML To The Screen
Aug 29, 2006 07:53 PM|LINK
Thanks, that worked. When I view the source the markup contains < and "
Is there a way to avoid this? Does it have anything to do with the way I am escaping my characters? I am just using the backslash "\". Is there a better technique? I know that by putting a "@" before your string has something to do with escaping characters.
sbyard
Contributor
5891 Points
1196 Posts
Re: Outputting XML To The Screen
Aug 30, 2006 09:44 AM|LINK
You can do something like below using an XML control
for finer display of output, use CSS or XSLT with the XML control
<%@ Page Language="C#" %>
<!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, EventArgs e)
{
Xml1.DocumentContent = @"<root>
<item>12345</item>
<item>"test test"</item>
</root>";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Xml ID="Xml1" runat="server"></asp:Xml>
</form>
</body>
</html>