Stringbuilder vs SQL FOR XML / XSL Transform
I have an interface that loads a list of documents depending on the tab clicked by a user.
I've been retrieving the data through XML from a SQL 2008 database with:
SELECT col1, col2 col3 FROM documents WHERE typeId = 4 FOR XML PATH('doc'), ROOT('documents')
Then tranforming the XML with an XSLT stylesheet. It all works fine.
To improve the experience I'm trying to use JQuery to load the list开发者_开发技巧 of documents when a tab is clicked. I was going to return a chunk of html to the client and replace the html of the div that contains the list of documents.
I have a couple of options, transform the XML from SQL to HTML and return the resulting string to the client
or
Forget about SQL XML and convert a datable into a HTML string using Stringbuilder like:
Dim _d As New Document
Dim dt As Data.DataTable = _d.GetDocuments(0, 0, 0, "2009", "")
Dim builder As New StringBuilder("<table><tr><td>Title1</td><td>Title2</td><td>Title3</td><td>Title4</td></tr>")
For i = 0 To dt.Rows.Count - 1
builder.Append("<tr><td>")
builder.Append("<a href=""http://www.google.ie"" target=""_blank"">")
builder.Append(dt.Rows(i).Item("documentTitle").ToString)
builder.Append("</a></td>")
builder.Append("<td>")
builder.Append(dt.Rows(i).Item("documentTitle").ToString)
builder.Append("</td>")
builder.Append("<td>")
builder.Append(dt.Rows(i).Item("documentTitle").ToString)
builder.Append("</td>")
builder.Append("<td>")
builder.Append(dt.Rows(i).Item("documentTitle").ToString)
builder.Append("</td></tr>")
Next
builder.Append("</table>")
dt.Dispose()
_d = Nothing
Return builder.ToString
Does anyone have a better way of implementing this?
Using Stringbuilder seems to win out over SQL XML in any tests I've tried.
Question might not have been clearer enough, found a good artcile with information I was after here http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html
精彩评论