0
saxParserを使用すると、endElementの完了をどのように確認できますか? Unforunately私はかなり大きなXMLファイルがあり、InsertHelperユーティリティに渡す前にすべてのデータをArrayListに格納する必要があります。 saxParserがループを完了したかどうかをテストするにはどうすればよいですか?Android + saxParser endElementはループを終了しましたか?
/**
* Called when tag opening (ex:- <name>AndroidPeople</name> -- <name>)
*/
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
currentElement = true;
if (localName.equals("StoreDetails")) {
//Log.i("TAG", "Store Details");
newKOPStoreVersion = attributes.getValue("stores_version");
//if (!dBHelper.getStoreXMLVersion().equals(newKOPStoreVersion)) { BUT BACK
Log.i("TAG", "Store Details Changed");
isStoreDetailsVersionChanged = true;
//dBHelper.deleteStoreDetail();
//currentValue = "";
//buffer = new StringBuffer();
dBHelper.setStoreXMLVersion(newKOPStoreVersion);
/*}
else BUT PACK
{
Log.i("TAG", "no change for KOP store version");
throw new KOPSAXTerminatorException();
}*/
}
}
/**
* Called when tag closing (ex:- <name>AndroidPeople</name> -- </name>)
*/
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
currentElement = false;
//if (isStoreDetailsVersionChanged == true) { PUT BACK
if (localName.equals("StoreID")) {
buffer.toString().trim();
storeDetails.setStoreId(buffer.toString());
} else if (localName.equals("StoreName")) {
buffer.toString().trim();
storeDetails.setStoreName(buffer.toString());
} else if (localName.equals("StoreDescription")) {
buffer.toString().trim();
storeDetails.setStoreDescription(buffer.toString());
} else if (localName.equals("Location")) {
buffer.toString().trim();
storeDetails.setLocation(buffer.toString());
} else if (localName.equals("Phonenumber")) {
buffer.toString().trim();
storeDetails.setPhoneNumber(buffer.toString());
} else if (localName.equals("VisualmapID")) {
buffer.toString().trim();
storeDetails.setVisualMapId(buffer.toString());
} else if (localName.equals("x")) {
buffer.toString().trim();
storeDetails.setCartX(buffer.toString());
} else if (localName.equals("y")) {
buffer.toString().trim();
storeDetails.setCartY(buffer.toString());
} else if (localName.equals("ClosestParkingLot")) {
buffer.toString().trim();
storeDetails.setClosestParkingLot(buffer.toString());
} else if (localName.equals("RelatedCategory")) {
buffer.toString().trim();
storeDetails.setRelatedCategory(buffer.toString());
//add buffer to arraylist - then loop array do the ih dance
dataList.add(storeDetails);
//this is my arraylist and I'm attempting to loop over it outside of this class, but it seems to only contain the last value of the xml, not all the values.
}
buffer = new StringBuffer();
//}
if (localName.equals("StoreDetails")) {
//Log.i("TAG","End StoreDetails");
isStoreDetailsVersionChanged = false;
//throw new KOPSAXTerminatorException();
}
}
/**
* Called to get tag characters (ex:- <name>AndroidPeople</name> -- to get
* AndroidPeople Character)
*/
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (currentElement) {
buffer.append(ch, start, length);
currentElement = false;
}
}
あなたがそれを見たい場合は、完全なコードを送信できます。
あなたが上書きできるエンドドキュメントメソッド – L7ColWinters