Forum:Document.evaluate not working

I have this javascript code in my user javascript page. (The alerts are just so I can see whats going on.) alert('test');

var theBrokenLinksxyz = document.evaluate('//a[contains(@title,"(page does not exist)")]',  document.body,   null,   6,   null);

alert('theBrokenLinksxyz='+theBrokenLinksxyz);

for (i=0;i<theBrokenLinksxyz.snapshotLength;i++){

var theMatch = theBrokenLinksxyz.snapshotItem(i).href.match(/\?title=(.*)&action/)[1];

theBrokenLinksxyz.snapshotItem(i).href = 'http://en.wikipedia.org/wiki/'+theMatch;}

alert('done'); When I run it all I see is the first alert. The one that says 'test'. This code (minus the alerts) was working recently then I had to go and mess around with it and now it doesnt work. The code came originally from greasemonkey userscripts. As you can see from that page this issue is not new. I am sure that I have reset it to exactly what was working before. When I run it on wikipedia I get all three alerts but the second one reads theBrokenLinksxyz=[object XPathResult] (oddly, this by itself doesnt seem to stop it from working. If it were working properly then theBrokenLinksxyz would be a list of all the links that contain (page does not exist) in their title. The loop would then redirect those links to wikipedia. I have no idea whats going on. Granpa 05:54, May 16, 2011 (UTC)

I found this webpage that explains document.evaluate but it doesnt tell me why this doesnt work. Granpa 12:24, May 16, 2011 (UTC)

And this page explaining XPath. Granpa 12:31, May 16, 2011 (UTC)


 * That output is correct, as objects do not evaluate as text when added to strings. Generally speaking, there's more than likely a much simpler way to accomplish what you're trying to do. What are you trying to get with this script?
 * You're taking a very roundabout route for accomplishing this, which probably comes from the fact that most people would use jQuery for this, which Greasemonkey doesn't have. Use this instead:

 $(function {	var links = $('a.new');	for(var i in links) {		links[i].href = 'http://en.wikipedia.org/wiki/' + links[i].title.substring(0, links[i].title.length - 22);	} });
 * That should do it.