[description] [p] blah blah [/description] [/p] で囲まれた説明を解析したい
<item>
<title>
Jon Greene named associate director for strategic planning and development at institute
</title>
<link>
http://www.vtnews.vt.edu/articles/2013/03/031513-ictas-greenepromotion.html
</link>
<description>
<p>In this new position, Jon Greene will be responsible for strategic research development of multimillion-dollar, interdisciplinary proposals at the Institute for Critical Technology and Applied Science,</p>
</description>
<pubDate>Fri, 15 Mar 2013 00:00:00 -0400</pubDate>
<guid isPermaLink="true">
http://www.vtnews.vt.edu/articles/2013/03/031513-ictas-greenepromotion.html
</guid>
<enclosure url="http://www.vtnews.vt.edu/articles/2009/10/images/M_09783greene-jpg.jpg" length="27715" type="image/jpeg"/>
<category>
Institute for Critical Technology and Applied Science
</category>
<category>College of Engineering</category>
<category>Research</category>
<category>National Capital Region</category>
</item>
私はデリゲートメソッドを使用していますNSXMLParser
:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
タイトルを取得するには、didEndElement
メソッドでこれを行うだけです:
if ([elementName isEqualToString:@"title"]){
self.aArticle.title = self.currentElementValue;
}
ただし、これを試してみるとうまくいきません。説明全体でノードに@"p"
アクセスする方法を考えてみてください。< p >
これに対するより良い方法/解決策はありますか?
foundCharactersNSLog
で文字列を印刷すると、次のようになります。
<
2013-03-18 00:42:31.978 newsFeed[67052:c09] string is p
2013-03-18 00:42:31.978 newsFeed[67052:c09] string is >
2013-03-18 00:42:31.979 newsFeed[67052:c09] string is Tysor will work closely with national security thrust leader Jon Greene and with cognition and communication thrust leader Jeff Reed, a professor of electrical and computer engineering in the College of Engineering and director of Wireless@VT.
2013-03-18 00:42:31.979 newsFeed[67052:c09] string is
2013-03-18 00:42:31.979 newsFeed[67052:c09] string is <
2013-03-18 00:42:31.979 newsFeed[67052:c09] string is /p
2013-03-18 00:42:31.979 newsFeed[67052:c09] string is >
今考えられる唯一の方法は< p >
、メソッド foundCharacters で見つかった場所を追跡し、囲んでいる< p >
タグ内の値に到達したかどうかをチェックするカウント変数を使用する方法です。