Xml server control

G

Guest

I could not find the answers for these two questions about in Xml server control

1. Is it possible for control to keep its ViewState? Even if I set EnableViewState = true the control does not seem to keep it, so I have to reload it on each postback

2. How do I display raw xml data? My control displays data with a stylesheet fine
XmlDocument doc = new XmlDocument()
doc.LoadXml (xml)
XslTransform trans = new XslTransform()
trans.Load (Server.MapPath("WalMartManifest2.xslt"))
xmlMain.Document = doc
xmlMain.Transform = trans

If I simply comment out the last line (Transform), no data is displayed..

Thanks

-Stan
 
S

Steven Cheng[MSFT]

Hi Stan,

From your description, you're wanting to use the ASP.NET xml Server Control
to display raw xml data in the page's response output rather than use some
certain xsl to transform them into html ,yes?

As this question, I'm afraid such operation is not allowed because each
ASP.NET web page will return as a certain ContentType, such as "text/html",
"text/xml", "image/gif" , "application/ms-excel" ...

By default , an aspx page is rendered as html page and its contenttype is
"text/html". And when we us the Xml Server control on it, we need to
specify a xls file or a XslTransform object to it so as to transform the
giving XmlDocuemnt intoHtml so that the result can be embeded into the
page's output response. If we don't transfer it and want to display raw xml
in the page, that means we want to mix a "text/html" type stream with
"text/xml" data which is apparent not allowed. And that's why the raw xml
data is not displayed. Do you think so?

If you do want to display xml data in page, you have the following means:
1. Change the reponse's ContentType to "text/xml" and then write pure xml
data into the response steam, such as:
XmlDocument doc = new XmlDocument();
DataSet ds = GetDataSet();

doc.LoadXml(ds.GetXml());
XmlDeclaration xmldecl;
xmldecl = doc.CreateXmlDeclaration("1.0","UTF-8",null);

//Add the new node to the document.
XmlElement root = doc.DocumentElement;
doc.InsertBefore(xmldecl, root);

//clear the response's original content
Response.Clear();
Response.ClearContent();
Response.ContentType="text/xml";

doc.Save(Response.OutputStream);
Response.End();

2. Or write out the XmlData As normal string text into a certain control
such as "Literal" or "Label" control, we need to html encode it so as to
display correctly. For example:

XmlDocument doc = new XmlDocument();
DataSet ds = GetDataSet();

string xml = ds.GetXml();
lblXml.Text = HttpUtility.HtmlEncode(xml);

#lblXml is a Label control

These are some of my suggestions. Hope helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Stan,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top