Using & (ampersand) in menu for links gives xml error

I’m using the following script dhtmlx.com/docs/products/dht … ading.html
(Which funnily enough on your site gives me the same error)

I have <script> var menu; function initMenu() { menu = new dhtmlXMenuObject("menuObj"); menu.setIconsPath("imgs/"); menu.attachEvent("onClick",function(id){var url = menu.getUserData(id,"url");location.href(url)}); menu.enableDynamicLoading("menu.php"); } </script>
But when the url has & in it it errors. Eg page.php?id=2&name=test
It stuffs up the xml

If I use php’s urlencode when it creates the xml, I get a link like:
mysite.com/quality%2Fquality … e%26id%3D3
This should be:
mysite.com/quality/quality.p … Title&id=3

Can I urldecode when retrieving or how do I do this?

Ok I figured this out though perhaps not the best method
In my PHP part that creates the xml I have this:

$url = str_replace("&", "%26", "$url");

Then in the main document I have

menu.attachEvent("onClick",function(id){var url = menu.getUserData(id,"url");url = url.replace("%26", "&");location.href(url)});