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('start');

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

alert('theBroknLinks.snapshotLength='+theBroknLinks.snapshotLength);

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

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

alert('theMatch='+theMatch);

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

alert('finished'); This code works on wikipedia but when I run it on wikia I always get snapshotlength=0. 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.

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) {		if(links[i].title.indexOf('talk:') == -1 && links[i].title.indexOf('Talk:') == -1) {			links[i].href = 'http://en.wikipedia.org/wiki/' + links[i].title.substring(0, links[i].title.length - 22);			links[i].title = 'wikipedia:' + links[i].title.substring(0, links[i].title.length - 22);			links[i].className = 'extiw';		}	} });
 * That should do it.


 * Bear in mind that there are some new links that I dont want to redirect.
 * For instance, a link to a talk page. Granpa 13:12, May 16, 2011 (UTC)


 * Updated the above code to exempt talk page links.