I’m starting up playing with Win8 development and I’m stucked in a problem since yesterday.
I’ve followed the MSDN example HERE to grab the data, I can retrieve the data (therefore, isn’t a connection limitation issue) but the problem is that regardless the settings I use, it always retrieve data as plain text, including \r\n characters.
I assume that if I could retrieve the structured XML would make my job easier, so I’m hoping you folks can put some lights on what I’m doing wrong.
Here’s my code snippet:
<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>
Here’s the value of 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"
And HERE is a similar question, which seems to be working using the responseXML responseType (although it’s not documented @MSDN guide).
Some things I already tried:
- Use a responseType as ‘document’ (as per the MSDN guide) and then retrieve result.responseXML;
- Omit the responseType argument;
- Use the approach above.
Now, I ran out of ideas. Any thoughts?
Try To use the following code to get the tags you want to play… (I believe it will do exactly what you want/need, connecting to a webpage and than work on the result based o the webpage/xml tags