How to check end element with empty tag on iPhone?
I'm newbie on iPhone development.I want to parse XML file like this to get attribute value.
<Root>
<element att_1 ="value1" att_2 ="value2" />
<element att_1 ="value1" att_2 ="value2" />
.
.
.
<Root/>
Normally XML file
<element att="..."> content <element/>
I use this at didEndElement
if([elementName isEqualToString:@"element"]){
// Do something
}
How to check empty tag ? Advice me Please. Thank you.
sorry for my bad english.
=====================================================================
Now I have new problem.when I run the application(simulator) it stuck and show message"Thread1:Stopped at breakpoint" in didSt开发者_StackOverflowartElement.I guess I do something wrong.
StudyList.xml
<StudyList>
<study description="20040311181130" modsInStudy="" pat_birth="19760822" pat_id="47-3450" pat_name="Ekachai Chaichanasiri" refPhy="" study_date="Sun Jan 11 00:03:00 ICT 2004" study_id="696122224" study_iuid="1.2.392.200036.9123.100.200.20040311181130"/>
<study description="XoranCAT Study" modsInStudy="" pat_birth="19821117" pat_id="63" pat_name="Wantana Areeprayolkij" refPhy="" study_date="Fri Jan 28 00:04:00 ICT 2005" study_id="" study_iuid="1.2.826.0.1.3680043.2.594.4041.16900.9840.32723.30648"/>
</StudyList>
Delegate
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"StudyList"]) {
//Initialize the array.
appDelegate.studyList = [[NSMutableArray alloc] init];
} else if ([elementName isEqualToString:@"study"]) {
//Initialize the study.
aStudy.patientBrith = [attributeDict objectForKey:@"pat_birth"] ;
aStudy.patientID = [attributeDict objectForKey:@"pat_id"];
aStudy.patientName = [attributeDict objectForKey:@"pat_name"];
aStudy.studyDate = [attributeDict objectForKey:@"study_date"];
NSLog(@"Patient name: %@",aStudy.patientName);
NSLog(@"Patient ID: %@",aStudy.patientID);
NSLog(@"Patient Birth: %@" ,aStudy.patientBrith);
NSLog(@"Study Date: %@" ,aStudy.studyDate);
}
NSLog(@"Process Element");
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//Nothing to do because XML file dose not have text node
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//End if XML file nothing to do.
if ([elementName isEqualToString:@"StudyList"]) {
return;
//Add study object in to array and release the object.
if ([elementName isEqualToString:@""]||elementName == nil) {
[appDelegate.studyList addObject:aStudy];
}
}
}
NSLog(@"Patient name: %@",aStudy.patientName);
NSLog(@"Patient ID: %@",aStudy.patientID);
NSLog(@"Patient Birth: %@" ,aStudy.patientBrith);
NSLog(@"Study Date: %@" ,aStudy.studyDate);
***Output of above is null. What wrong,Please tell me in right way.
Retain the value of string in this function
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
In - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
Check
if ([retainedString isEqualToString:@"" ] || [retainString == nil)
Then the value is empty.
精彩评论