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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Contributor
Posts: 8
Registered: ‎12-18-2012
My Device: BB 10
My Carrier: Mobilicity

How do I save a list item into an existing XML file

[ Edited ]


I would like to know  how to save a list item using the XmlDatamodel into another xml file.



Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: How do I save a list item into an existing XML file

This doesn't seem to be possible.

You'll have to extract the data item by item and write it to the file using QXmlStreamWriter or some other class.


  QFile file(filename);

  QXmlStreamWriter xmlWriter(&file);

  xmlWriter.writeTextElement("State", "state");



Another way is to implement your custom datamodel to perform both XML parsing and saving. This is a cleaner approach but harder to implement.


Andrey Fidrya, @zmeyc on twitter
New Contributor
Posts: 8
Registered: ‎12-18-2012
My Device: BB 10
My Carrier: Mobilicity

Re: How do I save a list item into an existing XML file

Thanks for the response. this is what I have. This what I tried based on your reply can you please advise.

import bb.cascades 1.0

Page {
     actions: [
                // create navigation panel actions here
                ActionItem {
                    title: qsTr("Create a report")
                    onTriggered: {
                        imgView.imageSource = "asset:///images/picture1br.png"
    Container {
        id: listCt
        // the childcount for the list item
       property alias listChildCount: chList.childCount
       property alias radioSelection: radioGp.selectedIndex
       ListView {
           id: chList
                   dataModel: XmlDataModel {
                       source: "models/Chapter2.xml"
                   listItemComponents: [
                       ListItemComponent {
                           type: "header"
                           Header {
                               title: ListItemData.title
                       ListItemComponent {
                           type: "listItem"
                       Container {
                        layout: DockLayout {}
                        LabelLabel {
                            text: ListItemData.title
                            bottomPadding: 50.0
                            leftPadding: 150.0
                        }// end of LabelLabel
                        RadioGroup {
                            id: radioGp
                            dividersVisible: false
                            preferredWidth: 150
                            minWidth: 149.0
                            Option {
                                id: option1
                                text: "H"
                            Option {
                                id: option2
                                text: "M"
                            Option {
                                id: option3
                                text: "L"
                            // When a new option is selected, we print the selection to the console.
                            onSelectedValueChanged: {
                                console.debug("New filling set: " + selectedValue);
                                if(selectedIndex >= 0) {
                               radioIndex = radioGp.selectedIndex
                        }//end onSelected
                    }//end radioGroup          
                    Divider {} // at the end of each list item   
                } // end of Container
            } // end of second ListItemComponent
        ] // end of listItemComponents list
        // When an item is selected, update the text in the TextField
        // to display the status of the new item
           onTriggered: {
                var selectedItem = dataModel.data();
                var page = getSecondPage();
                    xmlWriter.writeTextElement("State", radioIndex);
            }// end onTriggered
             property Page secondPage
                function getSecondPage() {
                   if (! secondPage) {
                 secondPage = reportFile.createObject();
                  return secondPage;
            attachedObjects: [
            ComponentDefinition {
            id: reportFile
            source: "../models/report.qml"
      } // end of ListView