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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Developer
Developer
klz
Posts: 127
Registered: ‎08-24-2011
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:

 

<listOfStations>
<station>
<StationIcon>0332.jpg</StationIcon>
<StationName>JD Inside</StationName>
<StationURL>http://www.jdinside.com/</StationURL>
<StationStreamURL type="pls">
http://www.panel-streaming.com/tunein.php/jdinside/playlist.pls
</StationStreamURL>
<StationButton/>
<StationButtonSelected/>
</station>
</listOfStations>

 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. 
 
Thanks! 
 
Thank you!
----------------------------
BlackBerry 10 Developer is looking for a job!
My Apps: Alchemy Game | Jam! | Traffic Signs: USA
My Blog: http://bb10pro.com
Please use plain text.
Developer
Developer
lew
Posts: 174
Registered: ‎03-05-2009
My Carrier: -

Re: Get a value when attribute exists - XML

i think the element 'StationStreamURL' doesnt always exist?

 

try wrapping into defensive code:

 

if(ListItemData.StationStreamURL){

  ListItemData.StationStreamURL[".data"]

}

 

 

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).

 

Please use plain text.