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
Posts: 29
Registered: ‎05-28-2013
My Device: z10
My Carrier: rogers
Accepted Solution

Parse Attribute

I have an XML like below. How can I retrieve "data" values in using qml?

 

<finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<name data="John"/>
<lastName data="Doe"/>
</finance>
Developer
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: Parse Attribute

Take a look at https://developer.blackberry.com/cascades/documentation/device_platform/data_access/working_with_xml...
You can write C++ wrapper to parse XML and then invoke it's methods from QML to retrieve "data" values.
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Contributor
Posts: 29
Registered: ‎05-28-2013
My Device: z10
My Carrier: rogers

Re: Parse Attribute

Do you have an example on how to access the attributes? 

Developer
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: Parse Attribute

Accordingly to documentation of XMLDataAccess attributes maps to QString. Just try to load it. If you have problems using XMLDataAccess you can also try to use QDomDocument: http://doc-snapshot.qt-project.org/4.8/qdomdocument.html

It parses XML document to QDomElements which have access to attributes.

-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Developer
Posts: 163
Registered: ‎04-28-2012
My Device: BlackBerry 9800
My Carrier: BlackBerry

Re: Parse Attribute

Hi,

 

     You can parse an attribute like this,

 

bool ClassName::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes)
{
  if(qName == "finance")
  {
    if(attributes.length() > 0)
    {
      for(int i=0;i<attributes.length();i++)
      {
        if(attributes.localName(i) == "module_id")
        {
            // here you will get the attribute value of module_id
             qDebug()<< attributes.value("module_id");
        }
      }
    }
  }

}

 

Thanks and Regards,

Naresh Kodumuri.