views:

127

answers:

1

Hello all,

I am parsing an xml file through Android Pull Parser technique.

first, have a look at the below xml file:

<childs>
    <students>
        <name> hello </name>
        <address> xyz </address>
    </stdents>      

    <students>
        <name> abc </name>
        <address> def </address>
    </stdents>      

</childs>

Consider that the above file i am parsing. Now, My problem is that I want to create separate array for name and address. so while parsing, i want to store 1st students data in name[0] and address[0] and next students in name[1] and address[1]. In short, array size is extending as and when more data is parsed.

is there any way to do so ? i mean to create dynamic extendable array ? or if there is another way to do so then pls help me to fight with this solution.

Pls help me and catch me out of this problem.

A: 

You could use Vector<String> and then (if you need an array) copy the data to array(s) using toArray method.

    Vector<String> v = new Vector<String>();
    for (int i=0; i<10; i++)
        v.add(new String(Integer.toString(i)));

    Object s[] = v.toArray();

    for(int i=0; i<10; i++)
        str = (String)s[i];

Another option:

    String a[] = {};
    v.toArray(a);
Asahi
@Asahi example? pls
PM - Paresh Mayani
@Asahi thanx a lot...now let me try it out in my problem way
PM - Paresh Mayani
However you should probably use ArrayList instead of Vector as Vector is syncronized.
alexanderblom
@Asahi Thanx a lot...You saved my life finally i have implemented Vector and then converted it into Array
PM - Paresh Mayani
But however...if any better and appropriate solution also welcomed
PM - Paresh Mayani
ArrayList is also an option - depending on your requirements to synchronization
Asahi
hey who has down-voted to this answer...it really helps me a lot
PM - Paresh Mayani