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
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to parse XML data coming from server BB10 Cascades Development

maybe the parser does not read <!CDATA[xxx]> as a text element.
i would suggest to do some research on that.
see
http://harmattan-dev.nokia.com/docs/library/html/qt4/qxmlstreamreader.html#isCDATA

seems somebody else had the same issue:
http://stackoverflow.com/questions/13702712/cdata-parsing-in-blackbery10
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All

Re: How to parse XML data coming from server BB10 Cascades Development

You can get the plain text of XML data and replace the CDATA with blank then parse it. Like the sample code :

QString plainString = htmlString;
    plainString.remove(QRegExp("<[^>]*>"));

 




p(^_^)q
Good good study, day day up
Contributor
Posts: 10
Registered: ‎05-12-2012
My Device: 9860

Re: How to parse XML data coming from server BB10 Cascades Development

[ Edited ]

Solution is Here  Smiley Very Happy

*************************My XML Example***********************

<?xml version="1.0" encoding="ISO-8859-1"?>
<document><item>
        <country_name>United Kingdom</country_name>
        <country_currency>GBP</country_currency>
</item><item>
        <country_name>United States</country_name>
        <country_currency>USD</country_currency>
</item><item>
        <country_name>Algeria</country_name>
        <country_currency>DZD</country_currency>
</item><item>

.......

</item>
    </document>

************************* Parse Here ************************

void  XMLapp::requestFinished(QNetworkReply* reply)
{
    myActivityIndicator->stop();
    // Check the network reply for errors.
    if (reply->error() == QNetworkReply::NoError)
    {
    QXmlStreamReader xml;
    QByteArray data = reply->readAll();
    xml.addData(data);
    while (!xml.atEnd())
    {
    xml.readNext();
  
    if (xml.isStartElement())
    {
       if (xml.name() == "country_name"  )
       {
           qDebug() << " ::::::::::: country_name ::::::::: "+xml.name().toString()+" ====== "+xml.readElementText();
       }
       if (xml.name() == "country_currency"  )
       {
           qDebug() << " ::::::::::: country_currency ::::::::: "+xml.name().toString()+" ====== "+xml.readElementText();
       }
    }
    }
    }
    else
    {
        qDebug()<< "Problem with the network";
    }

}

 

--------------------------------------------------------------------------------

Feel free to press the like button if it's help you.
Thanks,

Amrit