shorten load time for xml file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • milecimm
    New Member
    • Oct 2007
    • 24

    shorten load time for xml file

    Hi

    I have the below code. It works fine but it takes a long time to load on the browser page. Is there anything I can do to shorten this time?

    Also, I would like to search the file for documents with NAME starting with A, B, C, etc. How do I do that?

    Thanks for your help!

    aspx.vb page

    Code:
    Dim xdoc As New XPathDocument(xt)
           
    
            Dim nav As XPathNavigator = xdoc.CreateNavigator()
    
            Dim expr As XPathExpression
            expr = nav.Compile("/pf:CONTRACTS/pf:CONTRACT")
    
            Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable)
            namespaceManager.AddNamespace("pf", "http://namespace/")
    
     	expr.SetContext(namespaceManager)
    
            Dim nodes As XPathNodeIterator = nav.Select(expr)
    
    	If nodes.Count <> 0 Then
    
                Dim tr As String = Nothing
              
                For Each node As XPathNavigator In nodes
    
      		tr += "<td><a Target='_blank' href='http://www.urltosite.aspx?contract=" & node.SelectSingleNode("pf:ID", namespaceManager).Value & "'>" & node.SelectSingleNode("pf:NAME", namespaceManager).Value & "</a></td>"
    
     		For Each subNode2 As XPathNavigator In node.Select("pf:SUPPLIERS/pf:SUPPLIER", namespaceManager)
    
                        tr += "<td>" & subNode2.SelectSingleNode("pf:SUPPLIERNAME", namespaceManager).Value & "</td>"
    
                    Next
    
                    tr += "<td>" & node.SelectSingleNode("pf:ENDDATE", namespaceManager).Value & "</td>"
    
                    tr += "</tr>"
    
                Next
    
                Dim th As String = "<th width='50%'>Name</th><th width='30%'>Supplier</th><th width='20%'>End Date</th>"
    
                div1.InnerHtml = ("<table width='96%' border='0' cellpadding='0' cellspacing='0' border='0' class='datatable1'>" & th) + tr & "</table>"
    
            Else
    
                div1.InnerHtml = "No results for your search"
    
            End If

    aspx page

    Code:
    <div id="div1" runat="server" >   </div>
    Last edited by Dormilich; Mar 3 '10, 06:50 PM. Reason: Please use [code] tags when posting code
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I think the biggest problem is the string concatenation, eg using += or &. It's probably used thousands of times.

    Everytime a concatenation operator is used, the string containing the results so far is resized, and possibly reallocated/copied/destroyed. Try and estimate the size of your output beforehand by using node counts, and allocate a stringbuilder object accordingly.

    tips:
    Create your own string concat object
    VB StringBuilder class

    Further question: Are you allowed to expose the source data to your clients?

    Comment

    • milecimm
      New Member
      • Oct 2007
      • 24

      #3
      Hi

      Thank you very much. I will use your idea.

      Sorry, what do you mean with to be "allowed to expose the source data to your clients".

      I am new at .net and xml and any help will be appreciated.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        There were some other methods I could think of, which would have needed client access to your source data, but on further investigation, they're much slower.

        Comment

        Working...