0

我得到这样的回应

<NewDataSet>
    <Map>
        <URL>
           https://maps.google.co.in/maps?q=ABIL+House,+Ganeshkhind+Road,+Yashwant+nagar,+Pune,+Maharashtra&hl=en&sll=18.539118,73.834095&sspn=0.011169,0.021136&oq=ABIL+House&t=h&hnear=ABIL+House,+2,+Ganeshkhind+Rd,+Yashwant+nagar,+Pune,+Maharashtra+411007&z=16
       </URL>
    </Map>
</NewDataSet>

我必须解析 url 值才能在 web 视图中显示。如何解析具有两个开始标签的 xml 文件,这是我的代码:

 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{ 
    if ([elementName isEqualToString:@"Result"])    { 
        item = [[NSMutableDictionary alloc] init]; 
        currentUser =[[NSMutableString alloc] init]; 
    } 
} 

 - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{ 
    if ([elementName isEqualToString:@"Result"]) { 
        [item setObject:currentUser forKey:@"Result"]; 
        // [item setObject:currentPassword forKey:@"Name"]; 
        [users addObject:[item copy]]; 
    } 
} 

 - (void)parser:(NSXMLParser )parser foundCharacters:(NSString *)string
{ 
    if ([currentElement isEqualToString:@"Result"])  { 
            [currentUser appendString:string]; 
        } 
    /* if ([currentElement isEqualToString:@"Name"]) 
        { 
            [currentPassword appendString:string]; 
    }
    */ 
} 

 - (void)viewDidLoad 
{ 
        users = [[NSMutableArray alloc] init]; 
        NSURL *xmlURL = [NSURL URLWithString:@"http://abilcms.com.sv2.premiumwebserver.com/WebServiceStatus.aspx?UserID=demo@abil.com"];
        xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; 
        [xmlParser setDelegate:self]; 
        [xmlParser parse]; 
        NSLog(@"name=%@",currentUser); 
        statuslabel.text= currentUser; 
}
4

1 回答 1

0

这是一个关于 ios 中 xml 解析的教程,展示了它是如何完成的。http://theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial

这是另一个访问多级 XML 文档的教程

但据我所知,如果这是您的 XML 中唯一的 URL 标记,您应该将“Result”替换为“URL”,据我所知,NSXMLParser 会在这种情况下为您处理级别。当然,如果您需要访问此 XML 中的更多数据,您应该像第二个链接中的示例那样构建它。

于 2012-08-03T05:33:51.413 回答