05-04-2010 09:19 AM
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,
Solved! Go to Solution.
05-04-2010 08:59 PM
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.
XML Source Code:
<author>J K. Rowling</author>
<author>Erik T. Ray</author>
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?
05-04-2010 10:13 PM
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:
Now for some advice
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.
05-04-2010 10:17 PM
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.