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
Contributor
vvenu88
Posts: 24
Registered: ‎06-16-2011
My Device: Blackberry Z10
Accepted Solution

Failed to open XML input source

Hi,

I am trying to retrieve a RSS feed in XML format and display it in the QML file. 

Here is code snippet:

 

                QByteArray dataArray = reply->readAll(); //reply is QNetworkReply
		qDebug() << "dataArray " << dataArray.data();

		bb::data&colon;:XmlDataAccess xda;

		QVariant channelRootData = xda.load(dataArray, "/rss/channel/");
		if (xda.hasError()) {
			bb::data&colon;:DataAccessError error = xda.error();
			qDebug() << "JSON loading error: " << error.errorType() << ": "
					<< error.errorMessage();
			return;
		}

 HTTP request is successful but  XmlDataAcess is failing to parse the retrieved data.

but the same XmlDataAcess could parse static XML file with the following code

QVariant channelRootData = xda.load("app/native/assets/sample.xml", "/rss/channel/");

 Could any one help me.

 

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Failed to open XML input source

Please do not duplicate questions, under the options menu you can edit a post already posted.

 

I have asked the moderator to remove the previous one.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
vvenu88
Posts: 24
Registered: ‎06-16-2011
My Device: Blackberry Z10

Re: Failed to open XML input source

Something wrong has happened while posting the message because of which I happen to submit two messages.

I could not find 'option' to delete duplicate message.

 

Thanks for requesting to delete duplicate message.

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Failed to open XML input source

Yes there's no option to delete you would have to request from the moderator.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
vvenu88
Posts: 24
Registered: ‎06-16-2011
My Device: Blackberry Z10

Re: Failed to open XML input source

Any suggestions pls.

Developer
Zmey
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Failed to open XML input source

Try using this function instead:
xda.loadFromBuffer(dataArray, "/rss/channel/")

xda.load() treats the buffer as filename.

Andrey Fidrya, @zmeyc on twitter
Contributor
vvenu88
Posts: 24
Registered: ‎06-16-2011
My Device: Blackberry Z10

Re: Failed to open XML input source

Hi Zmey,

Thanks for the help.It worked.

Could you tell me why it is being treated as filename as clearly it is an object of QByteArray and XmlDataAccess has overloaded method.

 

Sorry if it is a silly question, I am a Blackberry java developer.

Developer
Zmey
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Failed to open XML input source

[ Edited ]

There are two overloads:

QVariant load (const QString &filePath, const QString &queryPath )
QVariant load (QIODevice *ioDevice, const QString &queryPath )

 

QString has an implicit constructor with QByteArray argument, so it was converting the QByteArray to QString while trying to match one of the overloads.

 


 

In C++ constructors taking one argument are implicit by default and are used in automatic conversions, so it's better to mark them as 'explicit' in your own classes to disable this behavior. Nothing can be done with library classes though.

 

Btw, if you happen to need to convert QByteArray to QString, do not rely on QString's implicit constructor as it will use Latin1 encoding by default, while UTF8 is usually needed.

 


Andrey Fidrya, @zmeyc on twitter
Contributor
vvenu88
Posts: 24
Registered: ‎06-16-2011
My Device: Blackberry Z10

Re: Failed to open XML input source

[ Edited ]

Is there a way to use the method
XmlDataAccess.load (QIODevice *ioDevice, const QString &queryPath=)

as the way, I have called it does not work.

Anyways I got the answer I am looking for.

Trying to understand the programming mistake I have done.

Developer
Zmey
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Failed to open XML input source

Edited my previous message back. Was looking at the wrong function declaration, sorry for the confusion. :smileyhappy:

 

To use QByteArray as QIODevice you'll have to wrap it into QBuffer first which provides QIODevice interface:

QBuffer buffer(&dataArray);
buffer.open(QIODevice::ReadOnly);
... = xda.load(buffer, ...)

More info:

http://qt-project.org/doc/qt-4.8/qbuffer.html#details

QFile's, sockets etc also implement this interface.

 

LoadBuffer works directly with the buffer without a stream wrapper.

 


Andrey Fidrya, @zmeyc on twitter