public XmlReader(ModelType modelType) {
this.modelType = modelType;
}
public ListLoadResult read(C loadConfig, Object data) {
Document doc = XMLParser.parse((String) data);
NodeList list = doc.getElementsByTagName(modelType.recordName);
ArrayList<ModelData> records = new ArrayList<ModelData>();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
Element elem = (Element) node;
ModelData model = newModelInstance();
for (int j = 0; j < modelType.getFieldCount(); j++) {
DataField field = modelType.getField(j);
String map = field.map != null ? field.map : field.name;
String v = getValue(elem, map);
model.set(field.name, v);
}
records.add(model);
}
int totalCount = records.size();
Node root = doc.getElementsByTagName(modelType.root).item(0);
if (root != null && modelType.totalName != null) {
Node totalNode = root.getAttributes().getNamedItem(modelType.totalName);
if (totalNode != null) {
String sTot = totalNode.getNodeValue();
totalCount = Integer.parseInt(sTot);