How do I get the XML of my search results?

So I’ve just started customising SharePoint Search results for the first time. It’s an area that I’ve never really touched before, to be honest – I’ve set up the crawling, and that’s the limit. Now I find myself reverse engineering a colleagues code in order to fix it.

Well, from what I can fathom, SharePoint search results actually come from the Search.asmx webservice in the _vti_bin of your site. The results are actually returned as XML, and in the web parts (not sure which ones, but certainly the Search Core Results web part) you then render this XML to HTML via XSLT. (If that means nothing to you, I’m afraid you’ll have to look it up. That concept is a whole can of worms. Maybe even a crate of worms. Anyway…)

An obvious question is, what does that source XML look like. Well, it’s whatever you get back from the web service, and there are various ways of find that, but I found a neat little solution on a post from Tobias Zimmergren’s blog (in fact, it’s an interesting looking series for a search rookie like myself – I think I’ll have to read that). I’ll blatantly plagiarise that in a bit. Basically, his idea was to define some XSLT that just emits the XML unaltered, and then look at what you’re getting back from the search service on the search results page.

So, to test, I copied the normal search results page (mine was in a search center) to give myself somewhere isolated to test in. I went to it – and it was all empty. Not surprising – there were no web parts. I added a Search Core Results web part:

Adding a Search Core Results Web Part

You might want to add a Search Box web part to give yourself somewhere to enter your search terms, though I’m a bit of a geek and was typing directly into the URL of the browser. For example,
will search for documents about, um, barnacles.

Results Page with Search Box and Core Results Web parts

Fine. Now we need to apply the XSLT. Edit the Search Core Results Web Part:

Editing the Web Part

and edit the XSL:

The XSL Editor

Blatant Plagiarism alert – Tobias’ XSL was just:

<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>

Note: Don’t just copy the above text – use this link. WordPress has changed the speechmarks in the code above, and it won’t work.

Apply it and voila – XML:

The Search Results page showing XML

Now I can get on with Styling it.

How do I get the XML of my search results?

4 thoughts on “How do I get the XML of my search results?

  1. […] Following on from my previous post, I’ve been looking some more at the code that one of my colleagues has created for styling up some search results. In it he needs the file extension for the item resulting, and he does this by, um, assuming that it’s the last 3 letters of the items URL. Yes, I am not amused. For example, if you look at the results from my last post… […]

Leave a Reply to » Hit Highlighting in SharePoint Search Document Titles Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.