Q:

jQuery AJAX success function with nested .each() - data is undefined

Right, this might be a bit difficult to explain. 
I have a jQuery AJAX request that's reading an XML file with a layout similar to this:
<root>
    <nodes>
        <node type="typeOne" name="nodeNameOne" />
        <node type="typeOne" name="nodeNameTwo" />
        <node type="typeTwo" name="nodeNameThree" />
        <node type="typeThree" name="nodeNameFour" />
        <node type="typeFour" name="nodeNameFive" />
    </nodes>

    <otherNodes>
        <otherNode name="nodeNameOne">Some value</otherNode>
        <otherNode name="nodeNameTwo">Some value</otherNode>
    </otherNodes>
</root>

This isn't something I have control over; the XML files are being generated by a third-party tool. 
What I want to do is read the value of the <node>s' name attribute, then use that to pull the value out of the corresponding <otherNode>, if it exists. 
This is what I've got in my success callback function:
function ParseFile(data, status, request){
    var types = ['typeOne', 'typeTwo']; //I don't care about all the <node>s

    alert(typeof data); //displays "object"

    types.each(function(entry, index){
        alert(typeof data); //displays "object"
        var typeNodes = jQuery(data).find('node[type="'+entry+'"]');

        typeNodes.each(function(){
            alert(typeof data); //displays "undefined"
            var name = jQuery(this).attr('name');
            /* The data object is undefined once you get inside this loop,
               so the following doesn't work. */ 
            var otherNode = jQuery(data).find('otherNode[name="'+name+'"]').text();
        });
    });
}

The problem is, I can't seem to access the data variable from within the second .else() loop.  Even if I declare a variable inside the first, var newData = data;, newData is undefined as well. 

A:

The reason this isn't working is that the jQuery function modifies data and tries to set it to the html fragment that it thinks that you've passed in.  However, you didn't pass valid html into it, so it sets it to undefined.  You need to copy data to another variable, rather than just set a refernce. 
Try doing
var myData = data.substr(0);

