Use setAttributeNS instead, something like this:
imageElement.setAttributeNS("http://www.w3.org/1999/xlink", "href", mypathvariable);
If you want to stick with:
imageElement.setAttribute("xlink:href", mypathvariable);
Then make sure you have this defined (typically on the root element), on some element that provides scope to where your attribute is being added:
someElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
The above also shows how to control a prefix in general.