This is my XML Format , for which i am using STAX for parsing and putting them inside my java Object called as FormBean
<id>38400016</id>
<name>admin</name>
<Brd units="5" sold="15">
</Brd>
<Brd units="5" sold="15">
</Brd>
<Brd units="5" sold="15">
</Brd>
class FormBean
{
double units;
double sold;
String name;
String id ;
}
See the way i am doing parsing using STAX
if (startElementName.equals("Brd"))
{
FormBean formbean = new FormBean();
// Here i am getting the attributes from Brd and setting them into FormBean
// as shown in below way
formbean.units = attribute.getValue(); // sets the unit value into FormBean
}
if (startElementName.equals("name"))
{
}
Now my question is , how can i set the name and id variables also within the same FormBean as i cant create a new instance of FormBean inside a id or an name tags ??
And at last i am adding these FormBean to an arrayList .
Have you considered using a library like
To do all the heavy lifting for you?