Convert string into XML object

i have a simple string that looks something like this…

var xml = "<mydata><name>Bob Smith</name><email>bob@smith.com</email></mydata>";

i’d like to take this string and convert it so i can run things like…

var names = xml.getElementsById("name");
var num_names = names.length;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Untitled Document</title>
        <link rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript">
            function parseXML(val) {
                if (document.implementation && document.implementation.createDocument) {
                    xmlDoc = new DOMParser().parseFromString(val, 'text/xml');
                }
                else if (window.ActiveXObject) {
                    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.loadXML(val);
                }
                else
                {
                    alert('Your browser can\\'t handle this script');
                    return null;
                }
                return xmlDoc;
            }
            var xmlDoc;
            window.onload = function() {
                xmlDoc = parseXML('<mydata><name>Bob Smith</name><email>bob@smith.com</email><name>Jon Doe</name><email>jon@doe.com</email></mydata>');
                var items = xmlDoc.getElementsByTagName('name');
                alert(items.length);
                for(var i = 0; i < items.length; i++) {
                    alert(items[i].childNodes[0].nodeValue);
                }
            };
        </script>
    </head>
    <body></body>
</html>