Javascript WinJS.xhr将XML字符串返回为文本(包括\n\r标记),而不是responseXML

Javascript WinJS.xhr将XML字符串返回为文本(包括\n\r标记),而不是responseXML,javascript,windows-8,winjs,Javascript,Windows 8,Winjs,我刚开始玩Win8开发,从昨天开始就遇到了一个问题 我按照MSDN示例获取数据,我可以检索数据(因此,这不是连接限制问题),但问题是,无论我使用什么设置,它总是以纯文本形式检索数据,包括\r\n字符 我认为,如果我能够检索结构化XML,我的工作会更容易,所以我希望你们能够了解我做错了什么 以下是我的代码片段: <div id="xhrReport"></div> <script> var xhrDiv = document.getElementById

我刚开始玩Win8开发,从昨天开始就遇到了一个问题

我按照MSDN示例获取数据,我可以检索数据(因此,这不是连接限制问题),但问题是,无论我使用什么设置,它总是以纯文本形式检索数据,包括\r\n字符

我认为,如果我能够检索结构化XML,我的工作会更容易,所以我希望你们能够了解我做错了什么

以下是我的代码片段:

<div id="xhrReport"></div>
<script>
    var xhrDiv = document.getElementById("xhrReport");
    xhrDiv.style.color = "#000000";

    WinJS.xhr({ url: "http://www.w3schools.com/xml/note.xml", responseType: "responseXML"})
        .done(
            function complete(result) {
                var xmlResponse = result.response; 

                xhrDiv.innerText = "Downloaded the page";
                xhrDiv.style.backgroundColor = "#00FF00"; //here goes my breakpoint to check response value

            },
            function error(result) {
                xhrDiv.innerHTML = "Got error: " + result.statusText;
                xhrDiv.style.backgroundColor = "#FF0000";
            },
            function progress(result) {
                xhrDiv.innerText = "Ready state is " + result.readyState;
                xhrDiv.style.backgroundColor = "#0000FF";
            }
        );

</script>

var xhrDiv=document.getElementById(“xhrReport”);
xhrDiv.style.color=“#000000”;
WinJS.xhr({url:http://www.w3schools.com/xml/note.xml,responseType:“responseXML”})
.完成(
功能完成(结果){
var xmlResponse=result.response;
xhrDiv.innerText=“下载页面”;
xhrDiv.style.backgroundColor=“#00FF00”//这里是我检查响应值的断点
},
函数错误(结果){
xhrDiv.innerHTML=“出现错误:”+result.statusText;
xhrDiv.style.backgroundColor=“#FF0000”;
},
功能进展(结果){
xhrDiv.innerText=“就绪状态为”+result.readyState;
xhrDiv.style.backgroundColor=“#0000FF”;
}
);
下面是xmlResponse的值

"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<!-- Edited by XMLSpy® -->\r\n<note>\r\n\t<to>Tove</to>\r\n\t<from>Jani</from>\r\n\t<heading>Reminder</heading>\r\n\t<body>Don't forget me this weekend!</body>\r\n</note>\r\n"
“\r\n\r\n\r\n\tTove\r\n\tJani\r\n\tRender\r\n\t这个周末别忘了我!\r\n\r\n”
这是一个类似的问题,似乎正在使用responseXML responseType(尽管@MSDN指南中没有记录)

有些事情我已经试过了:

  • 使用响应类型作为“文档”(根据MSDN指南),然后检索result.responseXML
  • 省略responseType参数
  • 使用上述方法

现在,我没有主意了。有什么想法吗?

尝试使用以下代码获取您想要播放的标签。。。(我相信它会完全满足您的需要,连接到一个网页,然后根据网页/xml标记处理结果

function connectToURL(){
    var url = "";

    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
         return;
    }            
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url,true);
    xmlHttp.send(null);
}

// your job will actually start on this one...
function stateChanged() {
        if(xmlHttp != null )
            if (xmlHttp[item.key].readyState == 4 ) {
                try {
                    var xmlDoc = xmlHttp.responseXML.documentElement.getElementsByTagName("TAGYOUWANTTOGET");
                    for (var i = 0; i < xmlDoc.length; i++) {
                       xmlDoc[i].getElementsByTagName("TAG")[0].childNodes[0].nodeValue
                    }
                } catch (e) {
                   //work on the exception
                }
            }
        }     
}

function GetXmlHttpObject(){
    var xmlHttp=null;
    try{
        xmlHttp = new XMLHttpRequest();
    }
    catch(e){
        try{
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e){
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
函数connectToURL(){
var url=“”;
xmlHttp=GetXmlHttpObject();
if(xmlHttp==null){
返回;
}            
xmlHttp.onreadystatechange=stateChanged;
open(“GET”,url,true);
xmlHttp.send(空);
}
//你的工作将从这个开始。。。
函数stateChanged(){
if(xmlHttp!=null)
if(xmlHttp[item.key].readyState==4){
试一试{
var xmlDoc=xmlHttp.responseXML.documentElement.getElementsByTagName(“TagYouWantGet”);
对于(var i=0;i
我认为您应该为responseType设置一个选项:“document”,就像:

  WinJS.xhr({
        url: "http://www.capital.bg/rss/?rubrid=" + groupId,
        responseType:"document"

    }).then(function (result) {
        console.dir(result.response);
    });

你好,埃米利安,谢谢你的建议!不幸的是,正如你在“已经尝试过的事情”部分所看到的,它在列表中。。。