storing integer in a int variable using NSXMLParser, in obj c
hii every one
i am doing a iphone project in that i need to take a int value from xml so how can i store a integer value which is stored in a xml, into a int variable using NSXMLParser (by parsing the 开发者_运维知识库xml)
can any one give me some examples,,, thanx in advance
Here is one way (assuming you already know how to use NSXMLParser)
xml:
<intVariable>10</intVariable>
code:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"intVariable"])
intVariable = [currentElementValue intValue];
[currentElementValue release];
currentElementValue = nil;
}
(currentElementValue and intVariable are mutable string and int members respectively).
精彩评论