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
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T
Accepted Solution

Parsing remote XML - QML

How would I parse this result

 

http://beermapping.com/webservice/locmap/3d16626bf36688f20f3246ca16be8a7a/2330

 

 

I have tried quite a few variations. I can parse this result fine

http://beermapping.com/webservice/locstate/3d16626bf36688f20f3246ca16be8a7a/md

 

But when I use the same structure on the first link, it doesnt work. Any help would be appreciated.

 

Code is here:

 

page 1 =

import bb.cascades 1.0
import bb.data 1.0
import bb.system 1.0
import bb.platform 1.0

Page {
    property string body
    property string infodatasource
    
    Container {
        Container {
            Label {
                id: statevalue
                visible: false
            }
            Label {
                id: datatext
                visible: true
            }
            Label {
                id: infotext
                textStyle.fontSize: FontSize.XXSmall

            }
            horizontalAlignment: HorizontalAlignment.Center
            bottomPadding: 10.0
            bottomMargin: 10.0
            Container {
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }
                DropDown {
                    id: state_selection
                    Option {
                        text: 'ALABAMA'
                        value: 'AL'
                    }
                    Option {
                        text: 'ALASKA'
                        value: 'AK'
                    }
                    Option {
                        text: 'ARIZONA'
                        value: 'AZ'
                    }
                    Option {
                        text: 'ARKANSAS'
                        value: 'AR'
                    }
                    Option {
                        text: 'CALIFORNIA'
                        value: 'CA'
                    }
                    Option {
                        text: 'COLORADO'
                        value: 'CO'
                    }
                    Option {
                        text: 'CONNECTICUT'
                        value: 'CT'
                    }
                    Option {
                        text: 'DELAWARE'
                        value: 'DE'
                    }
                    Option {
                        text: 'DISTRICT OF COLUMBIA'
                        value: 'DC'
                    }
                    Option {
                        text: 'FLORIDA'
                        value: 'FL'
                    }
                    Option {
                        text: 'GEORGIA'
                        value: 'GA'
                    }
                    Option {
                        text: 'HAWAII'
                        value: 'HI'
                    }
                    Option {
                        text: 'IDAHO'
                        value: 'ID'
                    }
                    Option {
                        text: 'ILLINOIS'
                        value: 'IL'
                    }
                    Option {
                        text: 'INDIANA'
                        value: 'IN'
                    }
                    Option {
                        text: 'IOWA'
                        value: 'IA'
                    }
                    Option {
                        text: 'KANSAS'
                        value: 'KS'
                    }
                    Option {
                        text: 'KENTUCKY'
                        value: 'KY'
                    }
                    Option {
                        text: 'LOUISIANA'
                        value: 'LA'
                    }
                    Option {
                        text: 'MAINE'
                        value: 'ME'
                    }
                    Option {
                        text: 'MARYLAND'
                        value: 'MD'
                    }
                    Option {
                        text: 'MASSACHUSETTS'
                        value: 'MA'
                    }
                    Option {
                        text: 'MICHIGAN'
                        value: 'MI'
                    }
                    Option {
                        text: 'MINNESOTA'
                        value: 'MN'
                    }
                    Option {
                        text: 'MISSISSIPPI'
                        value: 'MS'
                    }
                    Option {
                        text: 'MISSOURI'
                        value: 'MO'
                    }
                    Option {
                        text: 'MONTANA'
                        value: 'MT'
                    }
                    Option {
                        text: 'NEBRASKA'
                        value: 'NE'
                    }
                    Option {
                        text: 'NEVADA'
                        value: 'NV'
                    }
                    Option {
                        text: 'NEW HAMPSHIRE'
                        value: 'NH'
                    }
                    Option {
                        text: 'NEW JERSEY'
                        value: 'NJ'
                    }
                    Option {
                        text: 'NEW MEXICO'
                        value: 'NM'
                    }
                    Option {
                        text: 'NEW YORK'
                        value: 'NY'
                    }
                    Option {
                        text: 'NORTH CAROLINA'
                        value: 'NC'
                    }
                    Option {
                        text: 'NORTH DAKOTA'
                        value: 'ND'
                    }
                    Option {
                        text: 'OHIO'
                        value: 'OH'
                    }
                    Option {
                        text: 'OKLAHOMA'
                        value: 'OK'
                    }
                    Option {
                        text: 'OREGON'
                        value: 'OR'
                    }
                    Option {
                        text: 'PENNSYLVANIA'
                        value: 'PA'
                    }
                    Option {
                        text: 'PUERTO RICO'
                        value: 'PR'
                    }
                    Option {
                        text: 'RHODE ISLAND'
                        value: 'RI'
                    }
                    Option {
                        text: 'SOUTH CAROLINA'
                        value: 'SC'
                    }
                    Option {
                        text: 'SOUTH DAKOTA'
                        value: 'SD'
                    }
                    Option {
                        text: 'TENNESSEE'
                        value: 'TN'
                    }
                    Option {
                        text: 'TEXAS'
                        value: 'TX'
                    }
                    Option {
                        text: 'UTAH'
                        value: 'UT'
                    }
                    Option {
                        text: 'VERMONT'
                        value: 'VT'
                    }
                    Option {
                        text: 'VIRGINIA'
                        value: 'VA'
                    }
                    Option {
                        text: 'WASHINGTON'
                        value: 'WA'
                    }
                    Option {
                        text: 'WEST VIRGINIA'
                        value: 'WV'
                    }
                    Option {
                        text: 'WISCONSIN'
                        value: 'WI'
                    }
                    Option {
                        text: 'WYOMING'
                        value: 'WY'
                    }
                    onSelectedValueChanged: {
                        statevalue.text = state_selection.selectedValue
                    }
                    preferredWidth: 500.0
                    maxWidth: 500.0
                    minWidth: 500.0
                    bottomMargin: 50.0
                }
                
                Button {
                    text: "Submit"
                    onClicked: {
                        dataSource.source = "http://beermapping.com/webservice/locstate/3d16626bf36688f20f3246ca16be8a7a/" + statevalue.text
                        dataSource.load();
                    
                    }
                }


            }
        }
        Container {
            Divider {
                bottomMargin: 0.0
                minHeight: 40.0
                preferredHeight: 40.0
                maxHeight: 40.0

            }
            // Create a ListView that uses an XML data model
            ListView {
                dataModel: dataModel
                // Add appearance definitions for the list items using the
                // listItemComponents list
                listItemComponents: [
                    ListItemComponent {
                        type: "item"
                        
                        StandardListItem {
                            id: standardlistitem
                            // Display the value of an item's title property
                            // in the list
                            title: ListItemData.name
                            status: ListItemData.status
                            //description: ListItemData.id
                        }
                    }
                ] // end of listItemComponents list
                onTriggered: {
                    var data = dataModel.data(indexPath)
                    locationinfo.title = data.name
                    locationinfo.body = data.street + " " + data.city + ", " + data.state + " " + data.zip + " " + data.id
                    datatext.text = data.id
                    Qt.infodatasource = "http://beermapping.com/webservice/locquery/3d16626bf36688f20f3246ca16be8a7a/" + datatext.text
                    body = data.street + " " + data.city + ", " + data.state + " " + data.zip
                    locationinfo.show();
                    var infopage = info_page.createObject();
                    navpane.push(infopage);
                }
            } // end of ListView
        }// end of Container
    }// end of Page
    attachedObjects: [
        GroupDataModel {
            id: dataModel
            grouping: ItemGrouping.None
        },
        DataSource {
            id: dataSource
            source: "http://beermapping.com/webservice/locstate/3d16626bf36688f20f3246ca16be8a7a/" + statevalue.text
            query: "/bmp_locations/location"
            type: DataSourceType.Xml
            
            onDataLoaded: {
                dataModel.clear();
                dataModel.insertList(data);
            }
        },
        SystemDialog {
            id: locationinfo
            onFinished: {
                if (locationinfo.result == SystemUiResult.ConfirmButtonSelection) {
                    infotext.text = dataSource.source
                    dataSource.load();
                } else {
                  locationinfo.cancel();
                }
                }
            }
    ]
    onCreationCompleted: {
        dataSource.load();
    }
}

 

 

 

second page (the one having issues)

 

import bb.cascades 1.0
import bb.data 1.0
import bb.system 1.0
import bb.platform 1.0

Page {
    Container {
        Container {
            Label {
                id: test
                textStyle.fontSize: FontSize.XXSmall

            }

            Button {
                text: "Submit"
                onClicked: {
                    test.text = Qt.infodatasource

                }

            }
            Divider {

            }
        }
        ListView {
            dataModel: dataModel
            // Add appearance definitions for the list items using the
            // listItemComponents list
            listItemComponents: [
                ListItemComponent {
                    type: "item"

                    StandardListItem {
                        // Display the value of an item's title property
                        // in the list
                        title: ListItemData.name
                        status: ListItemData.status
                    }
                }
            ] // end of listItemComponents list
        } // end of ListView
    } // end of Container
    attachedObjects: [
        GroupDataModel {
            id: dataModel
            grouping: ItemGrouping.None
        },
        DataSource {
            id: dataSource
            source: Qt.infodatasource
            query: "/bmp_locations/location"
            type: DataSourceType.Xml

            onDataLoaded: {
                dataModel.clear();
                dataModel.insertList(data);
            }
        }
    ]
    onCreationCompleted: {
        dataSource.load();
    }
}

If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

Bit if background

I have the labels there to basically debug the variables, and they are all working perfectly. I also can pass the second page source variable as the url to a webview, and it displays the XML page properly. This leads me to believe that my listview is the issue. The problem is, the XML structure is exactly the same (excepting the page that works is an array with multiple results in the XML, the second page has only a single result).
If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

friendly bump

If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Developer
pyth
Posts: 506
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: Parsing remote XML - QML

just guessing...

 

I think the issue is your ListView. try adding the following function

                        ListView {
                            //your stuff...
                            //.....
                            
                            function itemType(data, indexPath) {
                                return "item";
                            }
                        }

 if that doesn't work, I suggest you add some qDebug messages to the onload-function of your datasource to see, what you are actually getting

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

Thank you very much I will give this a try. Any idea (if you have looked at the XML) why it wouldnt be returning results on page 2 when page 1 works perfectly?

If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Developer
pyth
Posts: 506
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: Parsing remote XML - QML

yes. it's because the standard XML Parser of QML has a very strange behaviour (not correctly filtering, troubles with namespaces, texts, deeper levels...). I gave up after some time, writing a QtXML Parser myself, and now using the GroupDataModel rather than the XMLDataModel

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

That is so very strange, the two XML files are formatted nearly identically.

If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

Unfortunately your addition didn't work. Can someone from RIM/BB comment perhaps? I'm trying to do this entirely in qml.
If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

http://www.opm.gov/xml/operatingstatus.xml

 

 

Similar thing, this will not parse. Anyone able to shed light on this?

If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.
Trusted Contributor
Sith_Apprentice
Posts: 207
Registered: ‎05-02-2010
My Device: various
My Carrier: AT&T

Re: Parsing remote XML - QML

It seems that any XML that retuns a single result (rather than a series), does not parse.

If you are the original poster (OP) and your issue is solved, please remember to click the "Accept as Solution" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the Star on the left of their post.
Please use plain text.