我正在使用NSXmlParser
從XML
獲取數據。在解析器委託方法我:無法使用NSXmlParser獲取數據
- (void)resetPassCallback: (NSData*) data{
NSLog(@"start parsing the data");
NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithData:data];
[nsXmlParser setDelegate:self];
BOOL success = [nsXmlParser parse];
if (success) {
NSLog(@"No errors %@", xmlArray);
} else {
NSLog(@"Error parsing document!");
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qualifiedName attributes: (NSDictionary *)attributeDict
{
element = elementName;
if([elementName isEqualToString:@"User"])
{
XmlDict = [[NSMutableDictionary alloc]init];
userId =[[NSMutableString alloc]init];
screenName =[[NSMutableString alloc]init];
xmlArray = [[NSMutableArray alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSLog(@"foundCharacters ::::: %@ :::: ", string);
[xmlArray addObject:string];
}
雖然我能夠分析數據,我沒有得到完整的數據。在控制檯上,日誌顯示:
foundCharacters ::::: 200 ::::
foundCharacters ::::: f1f47453-04d7-20c8-a9e1-406fdc89a2da ::::
foundCharacters ::::: test ::::
foundCharacters ::::: 62e2092a-eb6e-44ad-7a7b-3deb976569c1 ::::
foundCharacters ::::: Thomas ::::
xmlArray contents : (
"62e2092a-eb6e-44ad-7a7b-3deb976569c1",
Thomas
)
正如你可以看到,爲什麼我沒有得到在xmlArray
「測試」和其他值。
發佈完整的代碼 – santhu
你修改任何其他解析器的委託方法(S)'xmlArray'? – Akhilrajtr