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
VansFannel
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Consume a xml web service and parse it

I'm developing a HTML5 application for Blackberry OS 5+.

 

I have to get a remote xml file from http://domain.com/xxx/mTop and parse it to show it as a list.

 

I'm trying to do it with jQuery and AJAX but I get an issue with Same Origin Policy.

 

My question is, how can I get a remote XML file and show it as a list?

 

It is not really a file, it is a web service that returns a XML. If that web service returns a JSON, could I parse it?

New Contributor
apurv21
Posts: 2
Registered: ‎07-25-2012
My Device: 9630

Re: Consume a xml web service and parse it

You could use Javascript function eval to parse JSON.
New Contributor
Elsavies
Posts: 5
Registered: ‎07-06-2012
My Device: Curve 9300

Re: Consume a xml web service and parse it

im doing this using jquery,

 

function getColor(){

    var brand = $("#brand option:selected").val();//select a brand

    url = "domain/service.asmx/webservicename?brand="+brand;//this ws return colors after receive a brand

    $.ajax({

          type:"get",

url: url,

dataType: "xml",

success: function(xml){

        $("#color").empty();//clean the select input

        $(xml).find("colors").each(function(){//find all the colors tags in the xml

        $("<option selected='selected' value="+$(this).find("color").text()+">"+$(this).find("color").text()+"</option>").appendTo("#color");//append the color val to the select input called 'color'

        })

}       

     });

}

 

hope this help you

Developer
VansFannel
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Re: Consume a xml web service and parse it


Elsavies wrote:

im doing this using jquery,

 

function getColor(){

    var brand = $("#brand option:selected").val();//select a brand

    url = "domain/service.asmx/webservicename?brand="+brand;//this ws return colors after receive a brand

    $.ajax({

          type:"get",

url: url,

dataType: "xml",

success: function(xml){

        $("#color").empty();//clean the select input

        $(xml).find("colors").each(function(){//find all the colors tags in the xml

        $("<option selected='selected' value="+$(this).find("color").text()+">"+$(this).find("color").text()+"</option>").appendTo("#color");//append the color val to the select input called 'color'

        })

}       

     });

}

 

hope this help you


Do this code work? I'm connecting from my computer to a remote host and it doesn't work using a similar code but I'm getting a security error.

New Contributor
Elsavies
Posts: 5
Registered: ‎07-06-2012
My Device: Curve 9300

Re: Consume a xml web service and parse it

did you add the  <access uri="*" subdomains="true"/>  in the config.xml?, another problem i had was that jquery didnt work in OS 5, try your app in OS 6+ simulators too.

New Contributor
Elsavies
Posts: 5
Registered: ‎07-06-2012
My Device: Curve 9300

Re: Consume a xml web service and parse it

and its working fine for me in OS 6+, maybe i can help you more if you post part of your code.

Developer
VansFannel
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Re: Consume a xml web service and parse it

No, I'm testing my code on my PC using Safari. I haven't test it yet on simulator. But as far as I know there is a restriction to access remote data using javascript&colon; http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10

Re: Consume a xml web service and parse it

test in devce with the code give by other (above in same thread) it wont give any errror . this cause issue in browser or u must need to test with appserver (tomcat etc).

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
New Contributor
Elsavies
Posts: 5
Registered: ‎07-06-2012
My Device: Curve 9300

Re: Consume a xml web service and parse it

maybe this can be browser problems, i recommend you to use google chrome with the ripple extension, run your app in ripple and then package it with the last webworks sdk, after that try to run it in some blackberry simulator, if you post some of your code we can help you more.  

Developer
VansFannel
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Re: Consume a xml web service and parse it

[ Edited ]

This is my javascprit code:

// JavaScript Document
$(document).ready(function()
{
	$.ajax({
        type: "GET",
		url: "http://domain.com/incidencia/mTop",
		dataType: "xml",
		success: function(data) {
			console.log(data);
			$items = $(data).find('item');
 			$items.each(function(){
				var tipo = $(this).find('tipo').text();
				var porcentaje = $(this).find('porcentaje').text();
				$('<div class="items"></div>').html('<p>' + tipo + ' - ' + porcentaje + '</p>').appendTo('#page-wrap');
			});
		}
	});
});

 

And this is HTML:

 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
	<script src="libs/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="libs/jquery.mobile-1.1.1.min.js" type="text/javascript"></script>
    <script src="libs/myScript.js" type="text/javascript"></script>
</head>

<body>
	<div id="page-wrap">
     	<h1>Title</h1>
     </div>
</body>
</html>