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

Reply
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

XmlDataAccess list item one element

Is there a way to have effective xml parsing with XmlDataAccess?

 

For exemple I have this data:

<root>
<data id="1"></data>
<data id="2"></data>
</root>

 

And then this data,:
<root>
	<data id="1"></data>
</root>

 

 

When I have one item I must use a QVariantMap and when I have more I must use a QvariantList, that's not quite clear and consistent.

Please use plain text.
New Contributor
ahtram
Posts: 4
Registered: ‎12-10-2012
My Device: BB10
My Carrier: None

Re: XmlDataAccess list item one element

[ Edited ]

I faced the same problem too.

 

When there is only one child element under the root of xml file. You can't convert to result of XmlDataAccess.Load() into a QVariantList.The convert itself simply failed. Is this an intend behavior?

 

Some extra step need to be done to load an xml file into a QVariantList correctly.

I think we can improve this, no?

 

Please use plain text.
Regular Contributor
wibi_okezone
Posts: 51
Registered: ‎04-24-2013
My Device: Z10
My Carrier: Telkomsel

Re: XmlDataAccess list item one element

I have same problem too, has anyone solution ??

Please use plain text.
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: XmlDataAccess list item one element

I've chosen to load and parse data in C++ so, I can use a helper function:

 

QVariantList MyStringUtils::insureListData(QVariantMap data, QString name){
	QVariantList list = data[name].toList();
	if(list.size() == 0){
		QVariantMap temp = data[name].toMap();
		if(!temp.isEmpty()){
			list.append(temp);
		}
	}
	return list;
}

 

 

If you directly insert the data inside your datamodel in QML , use this workaround:

http://supportforums.blackberry.com/t5/Cascades-Development/ListView-not-loading-xml-using-DataSourc...

Please use plain text.