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
simon_hain
Posts: 16,190
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

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
Please use plain text.
Developer
javayoung
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900

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
Please use plain text.
Contributor
Amrit_Kumar
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  :smileyvery-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

Please use plain text.