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

Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Get a value when attribute exists - XML

Hello everyone,


So my problem is that I have no idea how to get a value when an attribute exists. I will try to be more detailed below.


I have a XML document with the following sctructure:


<StationName>JD Inside</StationName>
<StationStreamURL type="pls">

 I am receiving correct data from it and pass it ListView as a model. There is no mistake in this part of code. Here is a QVariant:


QVariant(QVariantMap, QMap(("StationButton", QVariant(QString, "") ) ( "StationButtonSelected" ,  QVariant(QString, "") ) ( "StationIcon" ,  QVariant(QString, "0332.jpg") ) ( "StationName" ,  QVariant(QString, "JD Inside") ) ( "StationStreamURL" ,  QVariant(QVariantMap, QMap((".data", QVariant(QString, "http://www.panel-streaming.com/tunein.php/jdinside/playlist.pls") ) ( "type" ,  QVariant(QString, "pls") ) )  ) ) ( "StationURL" ,  QVariant(QString, "http://www.jdinside.com/") ) )  ) 

I can get Station name in QML to set is as title for cell - ListItemData.StationName

Can get StationUrl - ListItemData.StationURL

Can get type of Station Stream Url (which is attribute) - ListItemData.StationStreamURL.type

BUT, I have no idea how to get Url (which is value). ListItemData.StationStreamURL.data doesn't work and returns 


TypeError: Result of expression 'chosenItem.StationStreamURL' [undefined] is not an object.


You would ask me what choseItem is. It is

 var chosenItem = dataModel.data(indexPath);

 I use it in onTrigerred to get an element which has been pressed. 


Any help will be appreciated. 
Thank you!
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Get a value when attribute exists - XML

i think the element 'StationStreamURL' doesnt always exist?


try wrapping into defensive code:







BUT, I have no idea how to get Url (which is value). ListItemData.StationStreamURL.data doesn't work and returns 

 your above code doesn't work, the key is NOT "data" but ".data". So you should use the javascript array accessor notation to retrieve that value (see my example above).


Posts: 11
Registered: ‎10-28-2012
My Device: Z10
My Carrier: N/A

Re: Get a value when attribute exists - XML

I searched how to obtain value of a tag when there are attributes for that tag using only QML (was parsing xml feeds directly with QML).


   <tag attr1="valattr1" attr2="valattr2">tagvalue</tag>
   <tag attr1="valattr1" attr2="valattr2">tagvalue</tag>


then inside ListView > listItemComponents > ListItemComponent > Container > Label:


ListItemData.tag[0].attr1, ListItemData.tag[0].attr2 etc for attributes and ListItemData.tag[0][".data"]

ListItemData.tag[1].attr1, ListItemData.tag[1].attr2 etc for attributes and ListItemData.tag[1][".data"]



Hope this help