Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an xml file which contains thousands of lines data.
I have converted that xml file into html it is displaying as per my requirement.
But it is taking more than 1 min to load complete data in page(mvc4 cshtml).

Can you please suggest me how to increase the loading speed to view content.

What I have tried:

C#
private static string ConvertXmlToHtmlTable(string xml)
    {
        //StringBuilder html = new StringBuilder("<table style="color#555;">");
        StringBuilder html = new StringBuilder("<!DOCTYPE html><html><body>");

        try
        {
            XDocument xDocument = XDocument.Parse(xml);
            XElement root = xDocument.Root;

            var xmlAttributeCollection = root.Elements().Attributes();
            #region Headings

            
            
            #endregion Headings
            
            foreach (var ele in root.Elements())
            {
                if (!ele.HasElements)
                {
                    string elename = "";




                    if (ele.HasAttributes)
                    {
                        IEnumerable<xattribute> attribs = ele.Attributes();
                        foreach (XAttribute attrib in attribs)
                        {
                            //elename += attrib.Name.ToString() + "=" + attrib.Value.ToString();
                            elename += attrib.Value.ToString() + "<span style="padding-removed30px;"></span>";
                        }

                    }


                    html.Append("<span id="elename" style="font-size:13px;padding-removed30px;">" + elename + "</span>");
                    html.Append("<span id="ele.Value" style=" font-size:13px;padding-removed30px;">" + ele.Value + "</span>");
                    

                    html.Append("<br />");

                }

                else
                {

                    string xmlValues = "";




                    if (ele.HasAttributes)
                    {
                        IEnumerable<xattribute> attribs = ele.Attributes();
                        foreach (XAttribute attrib in attribs)
                            //    elename += Environment.NewLine + attrib.Name.ToString() + "=" + attrib.Value.ToString();
                            xmlValues += Environment.NewLine + attrib.Value.ToString() + "<span style="padding-removed30px;"></span>";

                    }


                    html.Append("<span id="xmlValues" style="font-size:13px;padding-removed30px;">" + xmlValues + "</span>");

                    html.Append("<br /><span id="ConvertXmlToHtmlTable" style="width:300px;">" + ConvertXmlToHtmlTable(ele.ToString()) + "</span>");
                    
                    html.Append("<br />");
                }
            }
            
            html.Append("</body></html>");
        }
        catch (Exception e)
        {
            return xml;
            // Returning the original string incase of error.
        }
        return html.ToString();
    }
Posted
Updated 2-Sep-16 3:05am
v5
Comments
Richard Deeming 1-Sep-16 9:45am    
Start by profiling your code. It's quite likely that the bulk of the time will be spent by the browser downloading and parsing your massive HTML file, which is something you have no control over. The only solution to that would be to reduce the number of records you return.
DGKumar 2-Sep-16 5:20am    
Hi
Thanks for response ,
The xml files is converted and stored into string with in less time.
but while displaying the data in html taking too much time.
May be html content is high.
How to increase the speed of loading content in html.
Patrice T 2-Sep-16 0:11am    
How many records in XML and XML size ?
DGKumar 2-Sep-16 5:20am    
Hi
Thanks for response ,
The xml files is converted and stored into string with in less time.
but while displaying the data in html taking too much time.
May be html content is high.
How to increase the speed of loading content in html.
Richard Deeming 2-Sep-16 8:04am    
Then the problem is either with the length of time it takes to transmit the data over the network, or the length of time it takes the browser to parse and display the HTML.

Short of paying to upgrade your users' network connections and computers, the only thing you can do to improve the speed is to load less data.

Either provide a means to filter the data that's loaded; or split the data into multiple pages; or summarise the data in some way. How you do that will depend on what you're doing with the data once it's loaded.

Remember, there's no way a user is going to read through thousands of lines of data just to find the one row they need.

Well, i'd strongly recommend to read this: Converting XML to HTML[^] and this: Chapter 9 - Improving XML Performance[^].

All what i'm trying to say is: you have to use xml transformation via xslt to be able to increase the process of conversion xml to html.
Try!
 
Share this answer
 
C#
Hi All,
I am very happy that the simple pre tag whihc is amazing html tag is resolving my issue.
In string every thing is ready to display but i have been struggling that how to display in html view quickly. Finally i implemented that i have put my html string between pre tag. Now with in second the data is displaying.
Thank you one and all for support.
 
Share this answer
 
v2
The most obvious problem I see is that your code do not compile:
C#
html.Append("<span id="elename" style="font-size:13px;padding-removed30px;">" + elename + "</span>");
                    html.Append("<span id="ele.Value" style=" font-size:13px;padding-removed30px;">" + ele.Value + "</span>");

is not legal.

I think posting real code in question would help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900