Wednesday 17 December 2008

XPath in C#

string url = "http://www.example.com/somedata.xml";

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream());

string xmlstr = sr.ReadToEnd();

XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlstr);

XmlNode root = doc.DocumentElement;

// Get a single node
XmlNode tnode = root.SelectSingleNode("/FEED/SOURCE");

// Get all nodes that match a certain XPath expression
XmlNodeList alltitles = root.SelectNodes("/BOOK/TITLE");

There is a useful table of XPath syntax on this page.

Thursday 11 December 2008

BBC iPlayer is stealing my bandwidth (and slowing down my computer)

If you're a BBC iPlayer user and like to download programmes to your computer rather than streaming them, you will have downloaded the BBC iPlayer Download Manager. What the BBC didn't tell you (or not very clearly, at least) is that when you install the Download Manager, it creates a Windows Service running in the background on your PC which is constantly making use of your internet connection (even when you don't have the Download Manager running) to upload chunks of the programmes you've got downloaded to your library to other iPlayer users.
Don't panic, this is not neccessarily a bad thing - in fact when you downloaded those programmes you did so from other users who were uploading them through the Windows Service running on their PCs - but a few weeks ago my computer started running slower than normal and I was finding that streaming iPlayer videos would stop and re-buffer every few seconds. With a quick Google search I found that it could be caused by this background behaviour of the iPlayer software. There were a few suggestions for how to stop this invisible uploading but the correct method is to do the following:

Open the Windows Services Manager by going to Start > Run... (or Start > Search box on Vista) and typing services.msc and pressing Return.
Scroll down until you find KService.exe. Right-click on it and click Stop. When it has stopped, right-click on it again and select Properties. In the dialogue that appears change the Startup Type drop-down menu to Manual or Disabled (Automatic means it will start again next time you reboot which we don't want).

That's all there is to it. Clearly if everyone does this, the peer to peer system that allows you to download iPlayer programmes won't work as there'll lots of downloaders but no uploaders but it's worth knowing if, like me, the iPlayer Download Manager starts causing you problems.