Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Display xml in webform using xslDisplay xml in webform using xsl
Previous
 
Next
New Post
6/6/2007 7:09 AM
 

Hi,

       I'm new here. I was just wondering if anyone knew a simple way of displaying xml from SQL Server into ASP.NET using XSL. Here is my situation: I'm retrieving xml from xml server using SqlDataReader and displaying it using <asp:Label> . I do not want to use the DataGrid or DataView control. I was trying to use xslTransform but I don't think it can be used with the elements that I am using. Any thoughts or suggestions, anything would be welcome at this point. Thanks and Regards.
                                                                                    Kiesha

 
New Post
6/6/2007 7:39 AM
 
Use the ASP.NET xml control from the toolbox.

Lee B
Owner
S@W Designs
Outsourcing partner
Developer forums and Help.
 
New Post
6/6/2007 8:10 AM
 

Thanks for your response, I guess I should have included my code before so everyone could get a better look at what I am trying to do, here it is:

                               <%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<title>Section 1 From PATH Chapter 10</title>
<head>

    <script runat="server">
         Sub Page_Load()
            Dim ConnStr As String = "Data Source=SQLSERVER;Initial Catalog=myDB1;Integrated Security=SSPI"
            Dim SQL As String = "SELECT Col001 FROM PWM1001TEST"
            Dim PubsConn As New SqlConnection(ConnStr)
            Dim TitlesCmd As New SqlCommand(SQL, PubsConn)
            Dim Titles As SqlDataReader
            PubsConn.Open()
            Titles = TitlesCmd.ExecuteReader()
            Output.Text = "<table>"
            While Titles.Read()
                Output.Text &= "<tr>"
                Output.Text &= "<td>" & Titles.GetValue(0) & "</td>"
               
                Output.Text &= "</tr>"
            End While
            Output.Text &= "</table>"
        End Sub
    </script>
</head>
<body background="Picture1.jpg">
    <h1 align=center>
        Path Chapter 10 Example</h1>
    <asp:Label ID="Output" runat="server"></asp:Label>
</body>
</html>

 

                The only thing is that when I would switch to <asp:Xml> then the Output.Text would not work. Is there another display control that directly corresponds to <asp.XML like Output.Text relates to <asp:Label>? And is the functionality of a xsl somehow built in to the <asp:XML>? If not it should be :-)

 
New Post
6/6/2007 8:20 AM
 

Ok, I found out how the xsl is used in the asp:xml but the example I am looking at is from Microsoft and is at the bottom of my response

I was wondering if there was a way that I could read through my entire xml column of my database on the server like I did in my code and somehow substitute it for "menu.xml" in the below example. Thanks for helping, I've tried this before but became discouraged when I fell upon this problem before.

    

<asp:Xml id="Xml1" runat="server" DocumentSource="menu.xml" TransformSource="menu.xslt"></asp:Xml></P>
 
New Post
6/6/2007 11:01 AM
 

I figured out how to do it. I don't think this is the most efficient way to go about the task but it works and if anyone else is having problems with this subject then they can use it as a basis. I had to read in the XML from the server, place it in a dynamically created xml file on the fly and display that file in ASP.NET using the <asp:Xml> control. Here is the code if anyone may find it useful:

<%@ Page Language ="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.IO" %>

<script runat="server" language="C#">
void Page_Load(){
    Get_XML_Data();
    //Get_XML_DataGrid();
}
void Get_XML_DataGrid(){
    DataSet myDataSet = new DataSet();
    myDataSet.ReadXml(Server.MapPath("pubs.xml"));
    xmlDG.DataSource = myDataSet;
    xmlDG.DataBind();
}

void Get_XML_Data() {
    string strConnect = "Data Source=SQLSERVER;Initial Catalog=myDB1;Integrated Security=SSPI";
    SqlConnection objConnect = new SqlConnection(strConnect);
    SqlDataAdapter objCommand = new SqlDataAdapter("SELECT col FROM myTable where id = 1", objConnect);
    objConnect.Open();
    DataSet objDS = new DataSet();
    objCommand.Fill(objDS);
    objDS.DataSetName = "PubsList";
    if (!File.Exists(Server.MapPath("pubs.xml"))) {
        objDS.WriteXml(Server.MapPath("pubs.xml"), XmlWriteMode.IgnoreSchema);
    }
    XmlDocument XMLdoc = new XmlDocument();
    XMLdoc.Load(Server.MapPath("pubs.xml"));
    XslTransform XMLtrans = new XslTransform();
    XMLtrans.Load(Server.MapPath("ReadMe.xsl"));
    xmloutput.Document = XMLdoc;
    xmloutput.Transform = XMLtrans;
    objConnect.Close();
}
</script>

<asp:datagrid id="xmlDG" runat="server">
</asp:datagrid>
<asp:xml id="xmloutput" runat="server">
</asp:xml>

 

       However, the xsl I was using is now "out of date" according to W3C, anyone know where I can find a generic template? I have a HUGE xml file and it would be a serious pain if i had to construct another xsl file. Thanks

                                   

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Display xml in webform using xslDisplay xml in webform using xsl


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out