Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2006, 02:33 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADVICE WANTED: Which method is more efficient?

I currently have a site that uses ASP.NET, VB.NET, XML, and XSLT using XSL Transformation in ASP.NET. My current method is this:
Code:
<script runat="server">
    Sub Page_Load
             'Pull page_qs querystring variable
             Dim page_qs As String = Request.QueryString("page")
             'Load XML file w/page_qs variable selected and assign page properties
             Dim il_xmld As XmlDocument
             Dim il_nodelist As XmlNodeList
             Dim il_node As XmlNode
             'Create the XML Document
             il_xmld = New XmlDocument()
             'Load the Xml file
             il_xmld.Load("links.xml")
             'Get the list of name nodes
             il_nodelist = il_xmld.SelectNodes("/links/page[@id = '" & page_qs & "']")
             'Loop through the nodes
             For Each il_node In il_nodelist

             'Get an Attribute Value
             Dim page_id = il_node.Attributes.GetNamedItem("id").Value

             'Pull XML nodes
             dir_code = il_node.Item("dir_code").InnerText
             subdir1_code = il_node.Item("subdir1_code").InnerText
             subdir2_code = il_node.Item("subdir2_code").InnerText

             'Page path creator
             'If dir is empty
             path_slash = "/"
             If dir_code = "" Then
                 dir_path = ""
             Else
                 dir_path = dir_code + path_slash
             End If

             'If subdir1 is empty
             If subdir1_code = "" Then
                 subdir1_path = ""
             Else
                 subdir1_path = subdir1_code + path_slash
             End If

             'If subdir2 is empty
             If subdir2_code = "" Then
                 subdir2_path = ""
             Else
                 subdir2_path = subdir2_code + path_slash
             End If

             'If page is not empty
             If page_id <> "" Then
                 page_path = page_id
             End If

             'Declare XML and XSL file paths
             Dim xmlURL As String, xslURL As String
             xmlURL = "/DIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xml/" + page_path + ".xml"
             xslURL = "/DIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xslt/" + page_path + ".xsl"
             'Assign dynamic url for this page
             xslTransform.DocumentSource = xmlURL
             xslTransform.TransformSource = xslURL

             'Load XML
             Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
             xml.async = false
             xml.load(xmlURL)

             'Load XSL
             Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
             xsl.async = false
             xsl.load(xslURL)

    End Sub
</script>
<html>
<body>
    <form runat="server">
        <asp:Xml id="xslTransform" runat="server"></asp:Xml>
    </form>
</body>
</html>
But I was wondering, would it be more or less efficient for me to create a function that transforms the XML and XSLT files in the code using the transformNode method by calling the function from a label in the form tag? I guess I'm thinking something like this:
Code:
<script runat="server">
    Sub Page_Load
        Function webdata
            'Pull page_qs querystring variable
            Dim page_qs As String = Request.QueryString("page")
            'Load XML file w/page_qs variable selected and assign page properties
            Dim il_xmld As XmlDocument

            '.... SAME AS ABOVE
            'Load XML
            Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
            xml.async = false
            xml.load(xmlURL)

            'Load XSL
            Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
            xsl.async = false
            xsl.load(xslURL)

            'Transform file
            webdata.Text = xml.transformNode(xsl)
        End Function
    End Sub
</script>
<html>
<body>
    <form runat="server">
        <asp:Label id="webdata" runat="server" />
    </form>
</body>
</html>
NOTE: Please keep in mind that I'm a newbie to all of this, so I realize that my logic may not be correct in the second example.

Or is the difference so minor that it doesn't matter? I'd greatly appreciate some input on this. Thanks for any advice.

KWilliams
 
Old August 30th, 2006, 12:28 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are you trying to do here? Are you just trying to display the XML document that you loaded, or does the XSLT transform that XML into HTML? Whats the point of this?





Neil Timmerman
Programmer
Veris Consulting
 
Old August 30th, 2006, 04:58 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It transforms the XML and XSLT docs into HTML. I included the following code in my previous post for example #1, which was a mistake:
Code:
'Load XML
             Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
             xml.async = false
             xml.load(xmlURL)

             'Load XSL
             Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
             xsl.async = false
             xsl.load(xslURL)

This script pulls the data from a central XML doc, that is set up like this:
<internal_links>
<page id="1">
<title>Page 1</title>
<subdir1>main</subdir1>
...
</page>
<page id="2">
<title>Page 2</title>
<subdir1>sub</subdir1>
...
</page>
</internal_links>

and then pulls corresponding XML and XSLT docs depending on the first XML doc's properties. So it's like this:
xmlURL = page_path + subdir1 + "docs/xml" + pagename + ".xml"
xslURL = page_path + subdir1 + "docs/xslt" + pagename + ".xsl"

Which results in these two files being transformed:
xmlURL = "/DIRECTORY/docs/xml/page1.xml"
xslURL = "/DIRECTORY/docs/xslt/page1.xsl"

This all results in a transformation of the XML and XSLT docs for the entire site from one ASP.NET page. I hope that this makes more sense.

KWilliams
 
Old August 31st, 2006, 11:02 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, so is the primary difference between these two versions, is that one loops through "links.xml" and transforms each page for the whole site on the first page_load event of the first page the user hits, where as the second version transforms each page as they hit them, and you figure out which page they are on by a query string argument, right?

By the way I never found the end of the For Each loop in the first version. I also don't understand why the Function is inside the page_load event handler on the second version. Is that a VB thing? Also, don't functions have to have arguments in VB, so shouldn't that be a sub?

I am a bit of a "newb" to VB so pardon my dumb questions. I have quite a bit more experience with C, C++ and now C#.

TO get back to your original question of efficiency, if I understand what you are doing correctly, I think knowing which approach is more efficient is highly depentant on your users. Loading the links.xml one time, and transforming every xml document for every page in one single page load incurs unnecessary cost if the user never visits any of those other pages, or very few of them. If the user visits most pages, or a large number of pages, then perhaps it's worth it. Without knowing more I would go for the second approach, under the assumption that you simply don't know what the average user will do and how many pages they will visit, and this spreads the cost evenly yeilding a more consistent page load time. But this is all just back-of-the-envelope conjecture so take it for what its worth.

Neil Timmerman
Programmer
Veris Consulting





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server Advice Wanted kwilliams SQL Server 2000 1 June 27th, 2006 03:47 PM
ADVICE WANTED: Website Performance Issues kwilliams Classic ASP Professional 2 December 19th, 2005 04:13 PM
Most efficient overriding technique jcsdeveloper C# 4 December 7th, 2005 04:18 PM
Database search - more efficient way? SoC Classic ASP Basics 4 August 15th, 2004 08:56 PM
Paging Again Still Not Efficient alyeng2000 ASP.NET 1.0 and 1.1 Basics 0 March 4th, 2004 08:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.