开发者

storing integer in a int variable using NSXMLParser, in obj c

开发者 https://www.devze.com 2023-03-01 03:29 出处:网络
hii every one i am doing a iphone project in that i need to take a int value from xml so how can istore a integer value which is stored in a xml, into a int variable using NSXMLParser (by parsing th

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号