Web Dev Matters and Me

Web Development Matters - HTML, XML, C#, .NET, AJAX/Javascript(jQuery), CSS, XML-XSLT

ME - LIFE,Philippines, Tokyo, ECE, PhilNITS/JITSE,情報処理, 日本語

things about Philippines, gaming, C# development and web development, how to make money in stock trading

Web Dev Matters and Me

Get XML results for your Query (SQL 2008)

I'm still find it hard to squeeze all available optimization on my site. I successfully had facebook plugins in it after trying, and now I'm staring at the SQL Server database, which can be a potential bottleneck to my web app.


So, maybe it would be nice if I can simply get my query as XML and pass it directly to be rendered. This will eliminate additional mappings and will free me some rendering process too, which is sweet! ^_^



So, how to do it? Very simple...just use "FOR", "XML PATH" and TYPE

so, in this sample query...



         SELECT 'TEST Title' as title
        ,'SAMPLE Description' as [description]
        FOR
        XML PATH(''),
        TYPE
        


will produce 

<title>TEST Title</title>
 description SAMPLE Description </description



Simply replace the hard-coded string to column-names and you're making XML queries in no time. So, instead of mapping everything to some object/classes, I'll have this coupled by the presenter page to the view. Now, the only problem I have is to wait for weekends to continue doing my xslt site.






 

0 comments:

FB Connect