function test() {
	var r = document.getElementById('result');
	r.innerHTML = '';

	var XMLHTTP = $.ajax({
		url : $('#url').val(),
		async : false
	});

	if (XMLHTTP.responseXML) {
		var context = XMLHTTP.responseXML;
		if ($('context').value) {context = context.selectSingleNode($('context').value)}

		try {

			var nodes = context.selectNodes($('#xpath').val());

			for (var i=0; i < nodes.length; i++) {
				
				switch (nodes.item(i).nodeType) {
					case 1: case 9: {
						value = nodes.item(i).xml;
						break;
					}
					case 2: {
						value = nodes.item(i).nodeValue;
						break;
					}
					default : {
						value = nodes.item(i).text;
					}
				}
				
				value = value.replace(/&/g, '&amp;');
				value = value.replace(/</g, '&lt;');
				value = value.replace(/\n/g, '<br/>');

				var d = document.createElement('div');
				d.innerHTML = value;
				r.appendChild(d);
				var p = findXPath(nodes.item(i));
				if (p) {
					var d = document.createElement('div');
					d.className = 'xpath';
					d.innerHTML = 'Unique XPath: ' + p;
					r.appendChild(d);
				}
			}
		} catch (ex) {
			alert('Illegal XPath?\n\n' + ex);
		}
	} else {
		alert("Could not open '" + $('url').value + "'.");
	}
}

function findXPath(node, suffix) {
	try {
		if (node) {
			if (node.nodeType == 1) {
				var siblings = node.selectNodes('preceding-sibling::' + node.nodeName).length;
				return findXPath(node.parentNode, node.nodeName + ((siblings) ? '[' + (siblings + 1) + ']' : '') + ((suffix) ? '/' + suffix : ''));
			}
			return findXPath(node.parentNode, suffix);
		}
		return '/' + suffix;
	} catch (ex) {}
	return null;
}

function showXPath(e) {
	alert(findXPath(e));
}
