我試圖將iOS應用程序移植到Android。我不熟悉在Android中解析XML。你能幫我一下嗎?將iOS Xcode移植到Android(解析XML SAX)
這是我的XML文件的口味:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<settingA>1</settingA>
<settingB>sunday</settingB>
<description>HAdijoijaofijfosdifjsoidfjodsfjidsfojds</description>
</item>
</items>
在iOS中我遵循,包括髮現和閱讀的元素,例如一些步驟:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"terms"]) {
// Tag <terms> found, creating a list of oracoes
self.terms= [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"term"]) {
// Tag <term> found, creating a new Term object
term = [[Term alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"terms"])
{
return;
}
if([elementName isEqualToString:@"term"]) {
[self.oracoes addObject:term];
[term release];
term = nil;
} else {
if(tempString != nil && term != nil){
[oracao setValue:tempString forKey:elementName];
}
[tempString release];
tempString = nil;
}
}
// Read content
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSString *s = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if(!tempString)
{
tempString = [[NSMutableString alloc] init];
}
[tempString appendString:s];
}
也許所有這些代碼是無關緊要的。 ..但無論如何...我應該從哪裏開始? 有沒有任何簡單的把這個XML信息放到列表,數組中?
謝謝!
+1對於簡單XML。傑出的簡單性和力量。 –
謝謝湯姆!我會發布我在這裏做的! – RickON