-3

I need to parse file xml I have a link that display

<labels>
<label name="name1">
<description name="name1" url="http:............."/>
<description name="name2" url="http:............."/>
</label>
<label name="name2">
<description name="name1" url="http:............."/>
<description name="name2" url="http:............."/>
</label>
<labels>

and then display it on List. I get the reply of url as xml contain using this method

 if (reply) {
                if (reply->error() == QNetworkReply::NoError) {
                    int available = reply->bytesAvailable();
                    if (available > 0) {
                        int bufSize = sizeof(char) * available + sizeof(char);
                        QByteArray buffer(bufSize, 0);
                        int read = reply->read(buffer.data(), available);
                        response = QString(buffer);
                    }
                } else {
                    response =
                            QString("Error: ") + reply->errorString()
                                    + QString(" status:")
                                    + reply->attribute(
                                            QNetworkRequest::HttpStatusCodeAttribute).toString();
                }
                reply->deleteLater();
            }

How I can parse it and display item on list?

mobileDeveloper
  • 894
  • 2
  • 14
  • 35
  • 2
    Consider updating your question title so it is actually a question. – donturner Jun 06 '13 at 09:54
  • 1
    didn't get you what's the matter with the title. my problem is to parse an xml on blackberry 10. what is the problem with that? – mobileDeveloper Jun 06 '13 at 13:19
  • The problem is that StackOverflow is a question and answer website so posting a statement is likely to yield lower quality answers for you. Perhaps "How can I display XML in a List?" would be more suitable. – donturner Jun 24 '13 at 14:07

1 Answers1

2

XMLDataModel directly parse the Xml into a QVariantMap:

if (reply->error() == QNetworkReply::NoError) {
   XmlDataAccess xda;
   QVariantMap data = xda.load(reply).value<QVariantMap>();

   if (xda.hasError()) {
       bb::data::DataAccessError error = xda.error();
       qWarning() <<  " XML error: " << error.errorMessage();
   } else{
       emit requestSuccess(data);
   }
} else {
[...]

Access it with data["label"].value().at(0), etc...

Benoit
  • 1,922
  • 16
  • 25