Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将XML元素转换为本地javascript变量_Javascript_Xml - Fatal编程技术网

将XML元素转换为本地javascript变量

将XML元素转换为本地javascript变量,javascript,xml,Javascript,Xml,我是一名编程专业的学生,我正在寻求对我的项目的帮助 我无法将XML元素设置为可以在代码中使用的本地javascript变量。我认为这与这段代码有关,但我不确定如何更正代码。我正在使用本地网络主机。任何建议都将不胜感激 包含上下文的项目文件夹: 我很确定它与这个段有关:$(xmlDoc).find(“catship”).each(function(){code>$(xmlDoc).find(“catship”).length返回什么? var xmlToCatshipObjectList = fu

我是一名编程专业的学生,我正在寻求对我的项目的帮助

我无法将XML元素设置为可以在代码中使用的本地javascript变量。我认为这与这段代码有关,但我不确定如何更正代码。我正在使用本地网络主机。任何建议都将不胜感激

包含上下文的项目文件夹:


我很确定它与这个段有关:$(xmlDoc).find(“catship”).each(function(){code>$(xmlDoc).find(“catship”).length返回什么?
var xmlToCatshipObjectList = function() {

    var r = $.Deferred();

    $.get(xmlDoc, function(doc){
        console.log("xmlToCatshipObjectList");
        $(xmlDoc).find("catship").each(function(){

            var $this = $(this);
            var health = $this.find('health-hits');
            var speed = $this.find('speed');
            var catNumber = $this.find('cats');
            var shipX = $this.find('xpos');
            var shipY = $this.find(k'ypos');


            shipList.push(
                new catship(health, speed, catNumber, shipX, shipY)
            );
        });
    });

    setTimeout(function () {
        r.resolve();
    }, 2500);

    return r;
};


function catship(health, speed, catNumber, shipX, shipY){
    this.health = health;
    this.speed = speed;
    this.catNumber = catNumber;
    this.shipX = shipX;
    this.shipY = shipY;
}