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
New Contributor
jovin_
Posts: 3
Registered: ‎05-04-2010
My Device: Bold 9000
Accepted Solution

XML and Data Retrieval

Hey,

 

Not sure if this is the right section on the forum:

 

Just wondering if there was a way to retrieve data from an XML page.

 

For example, I want to create a BBApp that can request an XML page and once it has loaded retrieve all the adequate fields and load them as a graphical UI - without actually loading the page, essentially I just want to make it create the request, and get the XML Source Code and mine through the data in that XML Source.

 

Thanks in advance,

Jovin Sveinbjornsson

Jovin Sveinbjornsson
BlackBerry Developer Novice
Teaching myself to develop along side my university studies
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: XML and Data Retrieval

Are you wanting to build a BlackBerry Widget, a Web Page or a Java application?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
jovin_
Posts: 3
Registered: ‎05-04-2010
My Device: Bold 9000

Re: XML and Data Retrieval

I believe it would be a Widget that I would like to develop.

 

Essentially what I would like it to do is once the http request has been fulfilled it should search through the elements for specific values and output them on the screen as a specially formatted list.

eg.

XML Source Code:

<bookstore>
  <book category="CHILDREN">
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>

 

It should pull the first book category out, make that as a title object in the widget, then begin to pull out the other values as necessary and place them in a graphical list.

 

Does that clarify my question a bit?

Jovin Sveinbjornsson
BlackBerry Developer Novice
Teaching myself to develop along side my university studies
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: XML and Data Retrieval

Hi Jovin,

 

This can easily be done in a BlackBerry Widget.  You would use the built in AJAX support and the XMLHttpRequest object.

 

You can retrieve the content of the XML file via an AJAX call.  When it returns you can then access the ".responseXML" property that has the DOM document of your XML already parsed.  You just need to be sure to whitelist the domain in the config.xml file to allow access to that outside resource.  There are a bunch of samples and videos that explain this concept.

 

You would then loop through that result XML and create your HTML to reflect your data and insert it into the page.  A good tutorial on AJAX can be found here:

http://www.w3schools.com/ajax/default.asp

 

Now for some advice :smileyhappy:

 

If you are retrieving data and then displaying it as Web content inside a widget, I would really recommend formatting that content on the server into its HTML markup before sending it to your Widget in the AJAX request.  The reason I recommend this is that there is a lot of DOM manipulation of creating HTML nodes if you are parsing raw XML that is being returned.

 

If you return the already server side formatted HTML you can simply replace a section on your web page using innerHTML.  On a mobile device, if you can offload any of the work to a server it definitely helps for performance.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
jovin_
Posts: 3
Registered: ‎05-04-2010
My Device: Bold 9000

Re: XML and Data Retrieval

Thanks Tim,

 

That clarifies things a lot and helps me out with designing my widget. Hopefully I can get it working properly and be able to distribute it.

Jovin Sveinbjornsson
BlackBerry Developer Novice
Teaching myself to develop along side my university studies