如果xml属性发生变化,如何解析......'
例如
<Root>
<child name="", age="",phone="",address=""/>
</Root>
这是我通过网络服务器从iphone发出的第一个请求....我解析了xml ...
之后,当我请求相同的网址时...现在更新了我的xml子标记更改。
<Root>
<child name="",age="",phone="",address="",office="",mobile="",location=""/>
</Root>
添加了额外的三个属性..
如何处理这种方法..任何例子请发送...提前谢谢
答案 0 :(得分:0)
-(void)startParsingForSendFriendRequest:(NSString *)userID Friend:(NSString*)friendID
{
NSString *urlString =[NSStringstringWithFormat:@"http:///user_id=%@&friend_id=%@",userID,friendID];
////NSLog(@"urlString : %@",urlString);
NSURL *xmlURL = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:xmlURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]autorelease];
NSURLResponse *returnedResponse = nil;
NSError *returnedError = nil;
NSData *itemData = [NSURLConnection sendSynchronousRequest:request returningResponse:&returnedResponse error:&returnedError];
//NSString *itemString = [[[NSString alloc] initWithBytes:[itemData bytes] length:[itemData length] encoding:NSUTF8StringEncoding]autorelease];
//NSLog(@"itemString : %@",itemString);
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:itemData];
[xmlParser setDelegate:self];
[xmlParser parse];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
////NSLog(@"parserDidStartDocument");
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
////NSLog(@"parseErrorOccurred");
NSString * errorString = [NSString stringWithFormat:@"Error (Error code %i )", [parseError code]];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading data" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
//NSLog(@"didStartElement");
// NSLog(@"elementName : %@",elementName);
// NSLog(@"namespaceURI : %@",namespaceURI);
// NSLog(@"qualifiedName : %@",qualifiedName);
NSLog(@"attributeDict : %@",attributeDict);
[registerNewArr addObject:attributeDict];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
////NSLog(@"foundCharacters");
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
////NSLog(@"didEndElement");
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
if ([[[registerNewArr objectAtIndex:1]objectForKey:@"Transaction"]isEqualToString:@"loginxml"])
{
[(WakeuuupLoginScreenVC *)obj getRegisterResult:registerNewArr];
}
}
- (void)dealloc
{
[registerNewArr release];
[super dealloc];
}