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

Java Development

Reply
Contributor
Posts: 19
Registered: ‎06-30-2011
My Device: 9800
My Carrier: ingenieur

saving parsed element from xml into class which contains vector

hi everyone

i did already parsed my xml but now i want to save data into class there is some code

that is mu xml

<company name="Great Company, Inc"><address>Pearl Plaza Great Kuningan, Jakarta Indonesia</address><employee>

<firstname>Gardiary</firstname>

<lastname>Rukhiat</lastname>

<nickname>gardiary</nickname>

<salary>3400000</salary>

</employee>

<employee>

<firstname>Zinedine</firstname>

<lastname>Zidane</lastname>

<nickname>zidane</nickname>

<salary>2300000</salary>

</employee>

</company>

and now my java class

public class Employee {
            private String firstname;
        private String lastname;
        private String nickname;
            private Long salary;
            //getter and seter 

}

now company class

public class Company {
     private String name;
            private String address;

// there i don't know how to declare the Employee class as you can see the company have many employee

}
    in the main class i can get    

       getTagValue("firstname",eElement)
       getTagValue("lastname",eElement)
       getTagValue("nickname",eElement)
       getTagValue("salary",eElement))

which i have to save them so i can use them later

Thank you  very much i hope that i was so clear

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: saving parsed element from xml into class which contains vector

give your company a vector employees.
you already have a company object when you encounter the first employee so you can add it to this vector.
----------------------------------------------------------
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
Contributor
Posts: 19
Registered: ‎06-30-2011
My Device: 9800
My Carrier: ingenieur

Re: saving parsed element from xml into class which contains vector

sure i now that i have to do that but i didn't work with vecotorsand i have no idea about how to do so if you had any code it's going to be perfect man

thanks for your help

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: saving parsed element from xml into class which contains vector

http://www.blackberry.com/developers/docs/6.0.0api/java/util/Vector.html

you create one with new Vector();
you add elements with addElement.

what questions do you have in detail?
----------------------------------------------------------
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
Contributor
Posts: 19
Registered: ‎06-30-2011
My Device: 9800
My Carrier: ingenieur

Re: saving parsed element from xml into class which contains vector

i want to now how to declare this vector in class company and how to add these elements in my main class

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: saving parsed element from xml into class which contains vector

public class Company {
private String name;
private String address;
private Vector employees;

in the constructor you call
employees = new Vector();

to add an employee you use company.getEmployees().addElement(employee)
----------------------------------------------------------
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
Contributor
Posts: 19
Registered: ‎06-30-2011
My Device: 9800
My Carrier: ingenieur

Re: saving parsed element from xml into class which contains vector

so  may cmpany class now is

public class Company {
            private String name;
            private String address;
            private Vector employees;           
           
                //geter and setter
    public Company(){
       
        employees = new Vector();
}       
}


and in my main i have these string element which i have to save in company class

       getTagValue("firstname",eElement)
       getTagValue("lastname",eElement)
       getTagValue("nickname",eElement)
       getTagValue("salary",eElement))

 

so what can i docause i can't understand this employee down there is what exactly

company.getEmployees().addElement(employee) 

 

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: saving parsed element from xml into class which contains vector

no, you have to save these in an instance of the Employee class.
when the employee class is fully created (all attributes set) you add it to the company object.
----------------------------------------------------------
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
Contributor
Posts: 19
Registered: ‎06-30-2011
My Device: 9800
My Carrier: ingenieur

Re: saving parsed element from xml into class which contains vector

i'm really sorry i think i need some code

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: saving parsed element from xml into class which contains vector

maybe you can do some basic java course somewhere, there are also some online possibilities.
creating and filling a bean object should be covered in one of the earlier chapters.
----------------------------------------------------------
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