2010-03-08 74 views
0

我是新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內容它顯示正確的聯繫我們。我已經改變了網址堆棧溢出和搜索標題,它檢索標題正確。但我無法檢索標籤的屬性的內容。請幫助我。請指導我。謝謝

回答

0

您可以在您的查詢中使用// h3 [@ attribute ='something']]

您可以使用[元素屬性]獲取與該特定屬性相關的所有內容。