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

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 121
Registered: ‎02-08-2013
My Device: 9900
My Carrier: verizon

Parse XML data

Hi all,

 

I'm looking for a bit of help with regards to parsing data from a xml document into a list. I have read through the docs but I can't transfer what i learnt to parse a document from youtube.

 

Could anybody point me in the right direction please?

 

This is my code attempt 

 

QByteArray xml = reply->readAll();
		XmlDataAccess xda;
		QVariant obj = xda.loadFromBuffer(xml);
		
		if (xda.hasError()) {
		    cout << (xda.error().errorMessage().toAscii().data());
		} else {
			QVariantList c = obj.value<QVariantList>();
		    cout << "list len = " << c.size();
		    cout.flush();
		}

 

from a document that starts like..

 

<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://purl.org/atom/app#' 
xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' 
xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<id>http://gdata.youtube.com/feeds/api/users/testaccount/uploads</id><updated>2013-02-23T14:46:55.349Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<title type='text'>Uploads by testaccount</title><logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/testaccount'/>
<link rel='alternate' type='text/html' href='https://www.youtube.com/channel/UC6M6HAerGLmGZWjYk14nP2Q/videos'/>
<link rel='http://gdata.youtube.com/schemas/2007#action.getUploadToken' type='application/atom+xml' href='https://gdata.youtube.com/action/GetUploadToken'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/testaccount/uploads'/>
<link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/testaccount/uploads/batch'/>
<link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/testaccount/uploads?start-index=1&amp;max-results=25'/>
<link rel='next' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/testaccount/uploads?start-index=26&amp;max-results=25'/>
<author><name>testaccount</name><uri>https://gdata.youtube.com/feeds/api/users/testaccount</uri>
</author><generator version='2.1' uri='http://gdata.youtube.com'>YouTube data API</generator>
<openSearch:totalResults>63</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>


<entry><id>http://gdata.youtube.com/feeds/api/videos/I9AbSe5eEFk</id>
<published>2013-02-22T23:53:37.000Z</published><updated>2013-02-22T23:53:37.000Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='People' label='People &amp; Blogs'/><title type='text'>Fdssf</title>
<content type='text'>Fbfdf</content><link rel='alternate' type='text/html' href='https://www.youtube.com/watch?v=I9AbSe5eEFk&amp;feature=youtube_gdata'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/I9AbSe5eEFk/responses'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/I9AbSe5eEFk/related'/>
<link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='https://m.youtube.com/details?v=I9AbSe5eEFk'/>
<link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/testaccount/uploads/I9AbSe5eEFk'/>
<author><name>testaccount</name><uri>https://gdata.youtube.com/feeds/api/users/testaccount</uri>
</author><gd:comments><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#comments' href='https://gdata.youtube.com/feeds/api/videos/I9AbSe5eEFk/comments' countHint='0'/>
</gd:comments><yt:hd/><media:group>
<media:category label='People &amp; Blogs' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>People</media:category>
<media:content url='https://www.youtube.com/v/I9AbSe5eEFk?version=3&amp;f=user_uploads&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='5' yt:format='5'/>
<media:content url='rtsp://v2.cache7.c.youtube.com/CigLENy73wIaHwlZEF7uSRvQIxMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='5' yt:format='1'/>
<media:content url='rtsp://v2.cache7.c.youtube.com/CigLENy73wIaHwlZEF7uSRvQIxMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='5' yt:format='6'/>
<media:description type='plain'>Fbfdf</media:description><media:keywords/><media:player url='https://www.youtube.com/watch?v=I9AbSe5eEFk&amp;feature=youtube_gdata_player'/>
<media:thumbnail url='http://i.ytimg.com/vi/I9AbSe5eEFk/0.jpg' height='360' width='480' time='00:00:02.500'/>
<media:thumbnail url='http://i.ytimg.com/vi/I9AbSe5eEFk/1.jpg' height='90' width='120' time='00:00:01.250'/>
<media:thumbnail url='http://i.ytimg.com/vi/I9AbSe5eEFk/2.jpg' height='90' width='120' time='00:00:02.500'/>
<media:thumbnail url='http://i.ytimg.com/vi/I9AbSe5eEFk/3.jpg' height='90' width='120' time='00:00:03.750'/>
<media:title type='plain'>Fdssf</media:title><yt:duration seconds='5'/></media:group></entry>

 

 

thank you.

Developer
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All

Re: Parse XML data

[ Edited ]

Have you added any authentication for youtube when send a request? You can also check the response code to analysis any error.




p(^_^)q
Good good study, day day up
Highlighted
Developer
Posts: 121
Registered: ‎02-08-2013
My Device: 9900
My Carrier: verizon

Re: Parse XML data

yes I was adding token to the request properly, I have just finally gotten past this by using QXmlStreamReader instead.

 

Thanks for your reply.

Developer
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All

Re: Parse XML data

It is great to know your solution. Thank you.




p(^_^)q
Good good study, day day up