Xml server control

Discussion in 'ASP .Net' started by =?Utf-8?B?U3Rhbg==?=, Apr 29, 2004.

  1. 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
     
    =?Utf-8?B?U3Rhbg==?=, Apr 29, 2004
    #1
    1. Advertising

  2. 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
     
    Steven Cheng[MSFT], Apr 30, 2004
    #2
    1. Advertising

  3. 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
     
    Steven Cheng[MSFT], May 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew Louden
    Replies:
    1
    Views:
    7,098
    Scott M.
    Oct 11, 2003
  2. =?Utf-8?B?UGVyZG8=?=
    Replies:
    0
    Views:
    600
    =?Utf-8?B?UGVyZG8=?=
    Feb 6, 2004
  3. -
    Replies:
    2
    Views:
    443
    Alan Krueger
    Jul 29, 2005
  4. Tim
    Replies:
    0
    Views:
    213
  5. Erik Wasser
    Replies:
    5
    Views:
    515
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page