我正在使用 XmlSerializer 创建一个 XML 文件。我的代码如下。
Iterator<TypeClass> itr=dataarray.iterator();
while(itr.hasNext()){
try{
TypeClass type=itr.next();
xmlserializer.startTag("", "family");
xmlserializer.startTag("", "FamilyID");xmlserializer.text(type.getF_id());xmlserializer.endTag("", "FamilyID");
xmlserializer.startTag("", "FamilyHead");xmlserializer.text(type.getF_head());xmlserializer.endTag("", "FamilyHead");
xmlserializer.startTag("", "FamilyAddress");xmlserializer.text(type.getH_name());xmlserializer.endTag("", "FamilyAddress");
xmlserializer.startTag("", "Phone");xmlserializer.text(type.getPh_num());xmlserializer.endTag("", "Phone");
xmlserializer.startTag("", "Ward");xmlserializer.text(type.getW_num());xmlserializer.endTag("", "Ward");
xmlserializer.startTag("", "Latitude");xmlserializer.text(String.valueOf(type.getLat()));xmlserializer.endTag("", "Latitude");
xmlserializer.startTag("", "Longitude");xmlserializer.text(String.valueOf(type.getLon()));xmlserializer.endTag("", "Longitude");
xmlserializer.endTag("", "family");
}catch(Exception e){
Log.i("z", "inside while exception :"+e);
}
}
xmlserializer.endTag("", "Families");
FileWriter file=new FileWriter(familyxml);
file.write(writer.toString());
file.flush();
file.close();
我的问题是,在循环结束时,一些数据没有被添加到 XML 文件中。这是我得到的:
<family><FamilyID>~value~</FamilyID><FamilyHead>NINAN PHILIPOSE</FamilyHead><FamilyAddress>~value~</FamilyAddress><Phone>~value~</Phone><Ward>~value~</Ward><Latitude>0</Latitude><Longitude>0</Longitude></family><family><FamilyID>~value~</FamilyID><FamilyHead>MATHEW M C</FamilyHead><FamilyAddress>~value~
没有其他标签.?????