如何在iphone中解析标签的内容与属性?
问题描述:
我是新iphone development.I要分析,并从该链接检索在url.I的HTML文件中的特定内容有一个示例代码http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/如何在iphone中解析标签的内容与属性?
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser search:@"//h3"]; // get the page title
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];
NSLog(h3Tag);
mLabel.text = h3Tag;
他们检索的H3内容它显示正确的联系我们。我已经改变了网址堆栈溢出和搜索标题,它检索标题正确。但我无法检索标签的属性的内容。请帮助我。请指导我。谢谢
答
您可以在您的查询中使用// h3 [@ attribute ='something']]
或
您可以使用[元素属性]获取与该特定属性相关的所有内容。