Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel
Accepted Solution

Error"Couldnot get XML Document" and Connection failed:status 500 " when trying to parse contents in the xml.aspx file of my application.

[ Edited ]

Error"Couldnot get XML Document"   and    Connection failed:status 500 "  when trying to parse contents in the xml.aspx file of my application

 

 

 

my index.html is as follows:

 

 

 

 

                                                                                     index.html

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>XMLDataSource</title>
    <link href="s40-theme/css/s40-theme.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript" src="s40-theme/js/screensize.js"></script>
    <script language="javascript" type="text/javascript" src="js/main.js"></script>
    <script type="text/javascript" src="mwl-2.0.js"></script>
<script>
</script>
</head>
<body onload="xmlDataSource.init();">
    <div class="ui-page">
        <!-- header -->
        <div class="ui-header">
            <table class="header_table" border="0" cellspacing="0" cellpadding="0">
           <tr>
             <td class="header_table_td_height"><div class='ui-title'><h2>XMLDataSource</h2></div></td>        
           </tr>
         </table>
        </div>
        <div class="ui-content">

   <div class="ui-category-list" id="accordian">  

   </div> 
  </div>
    </div>   
</body>
</html>

 

 

 

 

 

My config.xml is as follows:

 

 

 

                                                 config.xml

 

 

<?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.0.22">
   
    <name>XMLDataSource</name>   

    <description>
        Web App demonstrating how XML formatted resouce can be retrieved by using XMLHttpRequest.
    </description>
    
   
    <icon src="icon.png"/>

    <content src="index.html"/>
    <license href="http://www.apache.org/licenses/LICENSE-2.0">
  Licensed under the Apache License, Version 2.0 (the "License");
  #you may not use this file except in compliance with the License.
  #You may obtain a copy of the License at
  #
  #http://www.apache.org/licenses/LICENSE-2.0
  #
  #Unless required by applicable law or agreed to in writing, software
  #distributed under the License is distributed on an "AS IS" BASIS,
  #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  #See the License for the specific language governing permissions and limitations under the License.
 </license>
   
   
    <feature id="blackberry.app" required="true" version="1.0.0.0" />

</widget>

 

 

 

 

 

and               my            main.js is as follows

 

 

 

                                               main.js

 

 

 

 


var xmlDataSource = {
 
 URL: "......any url.aspx",
 
 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','#items_"+i+"', 'ui-show', 'ui-hide'); " +
    "mwl.setGroupTarget('#accordian','#item_title_"+i+"', 'ui-open', 'ui-close'); return false;\">";  
  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-Takeof'\">";       
        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,application/xml"); 
  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,"text/xml");
       
       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 that my contents conatined in the urlaspx    are parsed  and shown when  the app is run.

 

 

Please use plain text.
Developer
srk2012
Posts: 672
Registered: ‎12-04-2012
My Device: BlackBerry 8520
My Carrier: Airtel

Re: Error"Couldnot get XML Document" and Connection failed:status 500 " when trying to parse contents in the xml.aspx file of my application.

Ok now working on the device without any issue  .

 

 

 

I want some changes wihich I will intimate again.

Please use plain text.