01-30-2013 06:25 AM - edited 01-30-2013 06:32 AM
Unable to parse the xml.aspx contained in the main.js.Iam geting the follwoing error" Could not get XML document and Connection failed: status 500
My main.js looks like
var xmlDataSource = {
URL: "http:www. --------------------- symbianxml.aspx", etc (sample)
init: function() {
//URL, success callback, failure callback
this.connect(this.URL, this.responseHandler, this.failureHandler);
},
/**
* Parses XML document into JS Object array
* @param xmlDoc XML Document
* @returns {Array} array of device objects
*/
parseResponse: function(xmlDoc) {
var chElements = xmlDoc.getElementsByTagName("channel");
var channels = [];
console.log(chElements.length);
for(var i=0; i < chElements.length; i++){
var channel = { };
for(var j=0; j < chElements[i].childNodes.length; j++){
var node = chElements[i].childNodes[j];
if(node.nodeType != 1){ //not an element node
continue;
}
channel[node.tagName] = node.textContent;
}
channels.push(channel);
}
console.log(channels.length);
return channels;
},
/**
* Handles the response, and displays device data in web app
* @param xmlDoc
*/
responseHandler: function(xmlDoc) {
var channels = this.parseResponse(xmlDoc);
var markup = "";
for(i=0; i < channels.length; i++){
markup += this.generateHTMLMarkup(i, channels[i]);
}
document.getElementById("accordian").innerHTML = markup;
},
/**
* Generates HTML markup to be inserted in to Web App DOM.
* @index i, index of the device
* @param device, device object
*/
/*
generateHTMLMarkup: function(i, channel){
var str ="";
str += "<div class='ui-category-list-item-title ui-close' id='item_title_"+i+"'" +
"onclick=\"mwl.setGroupTarget('#accordian','#i
"mwl.setGroupTarget('#accordian','#item_title_
str += "<img src=\""+ channel['image'] +"\" height=100% align=left />" + channel['name'] +"</div>";
str += "<div class='ui-category-list-item-body ui-hide' id='items_"+i+"'>";
str += "<div class='ui-list'>";
str += "<div class='ui-list-item'>"+ "id: " + channel['id'] +"</div>";
str += "<div class='ui-list-item'>"+ "type: " + channel['type'] +"</div>";
str += "<div class='ui-list-item'>"+ "language: " + channel['language'] +"</div>";
str += "<div class='ui-list-item'>"+ "bandwidth: " + channel['bandwidth'] +"</div>";
str += "<div class='ui-list-item'>"+ "cellnapid: " + channel['cellnapid'] +"</div>";
str += "<div class='ui-list-item'>"+ "link: " + "<a href=\""+ channel['link']+"\">Start video</a> </div>";
str += "</div></div>";
return str;
},*/
generateHTMLMarkup: function(i, channel){
var str ="";
str += "<div class='ui-category-list-item-title-for-Global-Take
str += "<img class='img-for-Global-Takeof' src=\"" + channel['image'] + "\" />" +
"<a href=\"" + channel['link'] + "\">" + channel['name'] + "</a>" + "</div>";
str += "<div class='ui-list-item'>"+ "link: " + "<a href=\""+ channel['link']+"\">Start video</a> </div>";
return str;
},
failureHandler: function(reason) {
document.getElementById("accordian").innerHTML = "Could not get XML document.<br>"+ reason;
},
/**
* Retrieves a XML resource in given URL by using XMLHttpRequest.
* @param url URL of the XML resource to retrieve
* @param successCb Called, when the XML resourece is retrieved successfully. Retreived XML Document is passed as argument.
* @param failCb Called, if something goes wrong. Reason in text format, is passed as argument.
*/
connect: function(url, successCb, failCb) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("Accept","text/xml,appl
xmlhttp.setRequestHeader("Cache-Control", "no-cache");
xmlhttp.setRequestHeader("Pragma", "no-cache");
var that = this;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 ){
if(xmlhttp.status == 200){
if(!xmlhttp.responseXML){
try {
//In case server didn't respond with correct MIME type for a XML file.
var domParser= new DOMParser();
var xmlDoc = domParser.parseFromString(xmlhttp.responseText,"te
successCb.call(that,xmlDoc);
} catch (e) {
failCb.call(that,"Response was not in a XML format.");
}
}else{
successCb.call(that,xmlhttp.responseXML);
}
}else{
failCb.call(that,"Connection failed: Status "+xmlhttp.status);
}
}
};
xmlhttp.send();
}
};
Please see the contents in main.js are parsed perfectly.
Solved! Go to Solution.
01-30-2013 08:07 AM
hey srk2012,
What does your config.xml file look like?
01-30-2013 08:19 AM - edited 01-30-2013 08:24 AM
My config.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0" rim:header="WebWorks Sample">
<name>XMLDataSource</name>
<description>
Web App demonstrating how XML formatted resouce can be retrieved by using XMLHttpRequest.
</description>
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<icon src="icon.png"/>
<content src="index.html"/>
</widget>
Iam eagerly waiting for your solution. Thanks for ur reply. Mr JRab
01-30-2013 08:28 AM
Hey srk2012,
From the looks of it, you have to "whitelist" the domain you are trying to access via XMLHttpRequest. Here is an example:
https://developer.blackberry.com/html5/documentati
Run through it using the remote domain you are trying to access. Good luck!
01-30-2013 08:51 AM
Now I have changed it to
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0" rim:header="WebWorks Sample">
<name>XMLDataSource</name>
<description>Web App demonstrating how XML formatted resouce can be retrieved by using XMLHttpRequest.</description>
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
<access uri="http://www.-------------------/symbianxml.aspx" subdomains="true"> (sample)
<access uri="*" subdomains="true" />
<icon src="icon.png"/>
<content src="index.html"/>
</widget>
similar to working project
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0" rim:header="WebWorks Sample">
<name>MyApp</name>
<description>This is HelloWorld.</description>
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
<access uri="http://www.google.com" subdomains="true" />
<access uri="*" subdomains="true" />
<icon src="icon.png"/>
<content src="index.html"/>
</widget>
01-30-2013 09:54 AM
I'm assuming it still doesnt work? if so are you getting the same error? a 500 error is usually a server side error -- is the file you are calling showing up properly? try navigating to it via the browser (mobile / desktop) and see what happens.
01-30-2013 12:56 PM - edited 01-30-2013 12:57 PM
Yes it is opening very fine, have adifferent and complete one with me which opens other than in the config.xml etc
02-01-2013 01:38 AM
Eagerly waiting for the solution to my query everyone in the community...