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
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

parsing multi level tags with using remote source

hi

 

i want to parse xml with QML using remote source

 

my xml is

 

<?xml version="1.0"?><news>
    <header newsid="11" title="دعواتللتظاهروداخليةمصرتهددبـالرصاص" scrnews="Channel" date=" 29/8/2013" time=" 20:40" srcid="2"  />

<commnet CommentID="5" Name="tests" Commenttext="this is comments"  newsid="11"    />
<commnet CommentID="4" Name="tests" Commenttext="this is comments"  newsid="11"   />
<commnet CommentID="3" Name="tests" Commenttext="this is comments"  newsid="11"    /><commnet CommentID="2" Name="user_Name" Commenttext="this is comments"  newsid="11"   /></news>

 how to do that ?

any help

Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing multi level tags with using remote source

attachedObjects: [
            GroupDataModel {
                id: dataModel_comments
                
                // Sort the data in the data model by the "pubDate" field, in
                // descending order, without any automatic grouping
                sortingKeys: [ "CommentID" ] //[ "pubDate" ]
                sortedAscending: false
                grouping: ItemGrouping.None
            },
            DataSource {
                id: dataSource123
                
                // Load the XML data from a remote data source, specifying that the
                // "item" data items should be loaded
                source: "http://10.121.10.139/simplehtmldom/getC.php?newsid=11"
   
              query: ""
                type: DataSourceType.Xml
                
                onDataLoaded: {
                    // After the data is loaded, clear any existing items in the data
                    // model and populate it with the new data
                    if (data)
                    {
                        console.log("in if check")
                    dataModel_comments.clear();
                    dataModel_comments.insertList(data)
                    myIndicator1232.setRunning(false);
                }
                    else {
                        console.log("in else check---->"+dataModel_comments.size())
                        
                        myIndicator1232.setRunning(false)
                      noComments.visible=true
                      	
                    }
                }
            
                
            }
        ]

 i am using the following code for groupdata model and attached objects

Developer
Posts: 164
Registered: ‎07-23-2013
My Device: Blackberry z10
My Carrier: Airtel

Re: parsing multi level tags with using remote source

your url link not work ------> http://10.121.10.139/simplehtmldom/getC.php?newsid=11

 

I think you are asking about json webservice.. am i right.. 

 

You just posted your code only here.. Explain your query briefly

___________________________________________________________________________________________

*************Plese *********LIKE**** & ****ACCEPT as Solution*** If you got suggestion for your Query.

@RAJESH SVM ----- Blackberry Mobile App Developer, Blaze, India.
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing multi level tags with using remote source

i know that link will not work globally, because that link is of my system

 

here is my code for listview

  Container {
        id: listviewContainer
        leftPadding: 20
        rightPadding: 20
        layout: StackLayout {
                orientation: LayoutOrientation.TopToBottom

            }
          
        // Create a ListView that uses an XML data model
        ListView {
            id: myListView
            dataModel: dataModel_comments
           
            // Use a ListItemComponent to determine which property in the
            // data model is displayed for each list item
            listItemComponents: [
                // The first ListItemComponent defines how "header" items
                // should appear. These items use a Label.
                ListItemComponent {
                    type: "header"
                    
                    Container {
                        background: Color.create("#83abccb8")
                        preferredWidth: 768.0
                        layout: DockLayout {
                        
                        }
                        
                        horizontalAlignment: HorizontalAlignment.Right
                        Label {
                            text: ListItemData.newsTitle
                            
                            horizontalAlignment: HorizontalAlignment.Right
                            // Apply a text style to create a large, bold font with
                            // a specific color
                            textStyle {
                                base: SystemDefaults.TextStyles.BigText
                                fontWeight: FontWeight.Bold
                                color: Color.Black
                            }
                        }
                    }
                },
                ListItemComponent {
                    type: "item"
                    
                    Container {
                        layout: StackLayout {
                                orientation: LayoutOrientation.TopToBottom
                            }
                    //Dock Layout top
                    Container {
                       topPadding: 20
                        horizontalAlignment: HorizontalAlignment.Fill
                        verticalAlignment: VerticalAlignment.Top
                               
                        layout: DockLayout {

                            }
                        Label {
                            id: countryLabel
                            verticalAlignment: VerticalAlignment.Top
                            horizontalAlignment: HorizontalAlignment.Left
                            text: ListItemData.country
                            textStyle.color: Color.LightGray                     
                        }
                    }
                        // The title and image content container
                        Container {
                            //       background: Color.create("#7554d3")
                            topPadding: 30
                            horizontalAlignment: HorizontalAlignment.Fill
                            verticalAlignment: VerticalAlignment.Center
                            layout: StackLayout {
                                orientation: LayoutOrientation.TopToBottom                           
                            }                          
                            
                            // Label for title
                            Label {
                                // The title is bound to the data in models/recipemodel.xml title attribute.
                                id: commentsLabel
                                text: ListItemData.Commenttext                                
                                horizontalAlignment: HorizontalAlignment.Right
                                verticalAlignment: VerticalAlignment.Top
                                multiline: true
                                textStyle.fontWeight: FontWeight.Normal
                                textStyle.fontStyle: FontStyle.Normal
                                textFormat: TextFormat.Plain
                                textStyle.fontSize: FontSize.XSmall
                                textStyle.color: Color.Black
                                }                           
                            Divider {
                                    horizontalAlignment: HorizontalAlignment.Center

                                }                       
                    }
                }
            ]
   
        }
        
        attachedObjects: [
            GroupDataModel {
                id: dataModel_comments
                
                // Sort the data in the data model by the "pubDate" field, in
                // descending order, without any automatic grouping
                sortingKeys: [ "CommentID" ] //[ "pubDate" ]
                sortedAscending: false
                grouping: ItemGrouping.None
            },
            DataSource {
                id: dataSource123
                
                // Load the XML data from a remote data source, specifying that the
                // "item" data items should be loaded
                source: "http://10.121.10.139/simplehtmldom/getC.php?newsid=11"
   
              query: "/root/" -------->what to write here ?
                type: DataSourceType.Xml
                
                onDataLoaded: {
                    // After the data is loaded, clear any existing items in the data
                    // model and populate it with the new data
                    if (data)
                    {
                        console.log("in if check")
                    dataModel_comments.clear();
                    dataModel_comments.insertList(data)
                    myIndicator1232.setRunning(false);
                }
                    else {
                        console.log("in else check---->"+dataModel_comments.size())
                        
                        myIndicator1232.setRunning(false)
                      	
                    }
                }
            
                
            }
        ]
    
    }
    onCreationCompleted: {
        // When the top-level Page is created, direct the data source to start
        // loading data
        dataSource123.load();     
        myIndicator1232.setRunning(true);
    }

 i am parsing xml data, not json

 

below is xml i am getting from calling the link

 

<?xml version="1.0"?><news>
    <header newsid="11" title="دعواتللتظاهروداخليةمصرتهددبـالرصاص" scrnews="Channel" date=" 29/8/2013" time=" 20:40" srcid="2"  />

<commnet CommentID="5" Name="tests" Commenttext="this is comments"  newsid="11"    />
<commnet CommentID="4" Name="tests" Commenttext="this is comments"  newsid="11"   />
<commnet CommentID="3" Name="tests" Commenttext="this is comments"  newsid="11"    /><commnet CommentID="2" Name="user_Name" Commenttext="this is comments"  newsid="11"   /></news>

 i want to know, how to parse this xml

Developer
Posts: 164
Registered: ‎07-23-2013
My Device: Blackberry z10
My Carrier: Airtel

Re: parsing multi level tags with using remote source

ListView {
id: stampList
objectName: "stampList"

layout: GridListLayout {
columnCount: 2
headerMode: ListHeaderMode.Standard
cellAspectRatio: 1.4
spacingAfterHeader: 40
verticalCellSpacing: 0
}

// This data model will be replaced by a JSON model when the application starts,
// an XML model can be used to prototype the UI and for smaller static lists.
dataModel: XmlDataModel {
source: "models/stamps.xml"
}

listItemComponents: [
ListItemComponent {
type: "header"

Header {
title: {
if (ListItemData.title) {
// If the data is loaded from XML, a title property is used for the title.
ListItemData.title
} else {
// If it is loaded from JSON and set in a GroupDataModel, the header info is set in ListItemData.
ListItemData
}
}
}
},
// The stamp Item
ListItemComponent {
type: "item"
StampItem {
}
}
] // listItemComponents

onTriggered: {

// To avoid triggering navigation when pressing the header items, we check so that the
// index path length is larger then one (one entry would be a group under a header item).
if(indexPath.length > 1) {
// When an item is selected we push the recipe Page in the chosenItem file attribute.
var chosenItem = dataModel.data(indexPath);

// Create the content page and push it on top to drill down to it.
var contentpage = contentPageDefinition.createObject();

// Set the content properties to reflect the selected image.
contentpage.contentImageURL = chosenItem.URL
contentpage.contentDescription = chosenItem.infoText

// Push the content page to the navigation stack
nav.push(contentpage);
}
}
}
}// Container
}// StampPage

attachedObjects: [

// This is the definition of the Content page used to create a page in the onTriggered signal-handler above.
ComponentDefinition {
id: contentPageDefinition
source: "ContentPage.qml"
}
]

onPopTransitionEnded: {
// Transition is done destroy the Page to free up memory.
page.destroy();
}


Refer stam collector app https://github.com/blackberry/Cascades-Samples/tree/master/stampcollector

___________________________________________________________________________________________

*************Plese *********LIKE**** & ****ACCEPT as Solution*** If you got suggestion for your Query.

@RAJESH SVM ----- Blackberry Mobile App Developer, Blaze, India.
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing multi level tags with using remote source

it is using xml that is in model folder

 

but i have to parse xml from remote link,

 

and  then bind that xml to groupdatamodel

and display in listview

 

for listview, this example is using xmlDataModel, but i have to parse xml from external link

Highlighted
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing multi level tags with using remote source

[ Edited ]

can anybody help me ?

i am using group data model not xmldatamodel

 

i want to parse xml like this

 

 

 

<header id="29" title="Sample" scrnews="Channel Ajazera" date=" 30/8/2013" time=" 5:31" srcid="1"  />
<commnet CommentID="12" Name="aaa" Commenttext="Testing Comments"  id="29" country="aaa"   />
<commnet CommentID="11" Name="aaa" Commenttext="Testing Comments"  id="29" country="Arab"   /><commnet CommentID="10" Name="onine" Commenttext="this is comments"  newsid="29" country="abc"   /></news>

 

Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing multi level tags with using remote source

can anybody help me in this ?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: parsing multi level tags with using remote source

@umairqureshi_6 I and I believe others have real problems with posts like these (you are not the only one) where you just dump some code with a current status report.

 

You will get much better results by limiting the code to where your probem lies and specifically stating what the problem is and what you have tried so far.

 

Not many of us have the time to look though large amounts of code trying to work out what you are on about and the posts come across as just asking for code of which I'm sure the majority of us really don't have the time to do (unless we've written it already).

 

Help us help you and narrow down the problem you have clearly and concisely.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing multi level tags with using remote source

thanks for correcting me

 

i just want to parse xml given above using remote xml

which contains header and listitem

but the problem i am facing is, i am unable to parse the data using group data model

 

i have done the same thing using xmldatamodel

but how to do that using group data model for remote url