我得到这样的回复
<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>
我必须解析网址视图中显示的网址值。如何解析具有两个开始标记的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;
}
答案 0 :(得分:0)
这是一个关于ios中xml解析的教程,展示了它是如何完成的。 http://theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial
以下是访问multi level XML documents
的另一个教程但据我所知,如果这是XML中唯一的URL标记,则应将“Result”替换为“URL”,因为据我所知,NSXMLParser将在这种情况下为您处理级别。当然,如果您需要访问此XML中的更多数据,则应该像第二个链接中的示例一样构建它。