2013-03-26 80 views
1

如何解析xcode中的這個xml。這很緊急。在xcode中解析XML

<?xml version="1.0" encoding="utf-8"?> 
<url> 
    <string name="address">SomeValue</string> 
</url> 
+1

XMLParser的使用和執行這些2或3名代表像開始和結束...... –

+1

嘗試新鮮事物????試試這個https://www.google.co.in/search?q=xml+parsing+%2B+xcode&aq=f&oq=xml+parsing+%2B+xcode&aqs=chrome.0.57j0l3j62l2.5308&sourceid=chrome&ie=UTF-8 –

+1

請看看這個[鏈接] [1]它可以幫助你 [1]:http://stackoverflow.com/questions/2733286/nsxmlparser-with-multiple-attributes – Tendulkar

回答

2

看看下面的代碼,它可以幫助你:)

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
     attributes:(NSDictionary *)attributeDict { 

     if([elementName isEqualToString:@"string"]) 
      urlStr = [[NSString alloc] init]; 

    } 

    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 
     if(!currentElementValue) 
      currentElementValue = [[NSString alloc] init]; 

     currentElementValue = [NSString stringWithFormat:@"%@",string]; 
    } 

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
    { 
     if([elementName isEqualToString:@"string"]) 
      urlStr = [NSString stringWithString:currentElementValue]; 

    } 

    - (void)parserDidEndDocument:(NSXMLParser *)parser { 

    }