2011-08-04 23 views
0

我想讀一下包含以下信息東西從IOS文件構建一個字符串

<TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Arial' SIZE='10' COLOR='#000000' LETTERSPACING='0' KERNING='0'>Kiran</FONT></P></TEXTFORMAT> <TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Arial' SIZE='10' COLOR='#000000' LETTERSPACING='0' KERNING='0'> Ajay</FONT></P></TEXTFORMAT></isText><isValue></isValue><isCorrectAnswer></isCorrectAnswer>

中,我需要一個字符串,它開始與<p/p>何爲結尾的文件最好的方法。

* *我的想法 1.Reading由字符的字符和檢查

2,使用的NSXMLParser解析上述

請幫我出這是很好的一個,給其他你的建議比這種方法,如果你有任何好的技術。

您的建議對我更有價值。 謝謝大家。

+1

格式將是很好。 – Perception

+0

感謝您的建議 – ajay

+0

我會修改它.. – ajay

回答

0

您可以嘗試使用TouchXML: TouchXML installation

這裏是解決您的問題代碼:

NSMutableArray *res = [[NSMutableArray alloc] init]; 
//xmlInput is your string as NSString 
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:[xmlInput dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil] autorelease]; 

NSArray *nodes = NULL; 
nodes = [doc nodesForXPath:@"////P" error:nil]; 

for (CXMLElement *node in nodes) { 
    NSMutableDictionary *item = [[NSMutableDictionary alloc] init]; 
    [item setObject:[node XMLString] forKey:@"p"];   
    [res addObject:item]; 
    [item release]; 
} 
NSLog(@"%@", res); 
[res release];