- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试解析一些简单的东西,但我不知道该怎么做..我已经解析了之前有一些 xml,但这个结构没有任何内容,所以我有点迷失。
这是 xml。
<item>
<title><![CDATA[Preview: Courtney Crumrin and the Night Things Special Edition]]></title>
<description><![CDATA[]]></description>
<pubDate>Tue, 20 Dec 2011 11:52:48 -0800</pubDate>
<link>http://www.comicbookresources.com/?page=preview&id=10864</link>
<guid>http://www.comicbookresources.com/?page=preview&id=10864</guid>
</item>
This is how I am currently parsing the xml
#pragma mark - Parsing lifecycle
- (void)startTheParsingProcess:(NSData *)parserData
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process
[parser setDelegate:self];
[parser parse]; // starts the event-driven parsing operation.
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"title"])
{
self.titleString = [[NSMutableString alloc] init];
}
if ([elementName isEqualToString:@"description"])
{
self.descriptionString = [[NSMutableString alloc] init];
}
if ([elementName isEqualToString:@"link"])
{
self.linkString = [[NSMutableString alloc] init];
}
if ([elementName isEqualToString:@"guid"])
{
self.titleString = [[NSMutableString alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
NSMutableString *dicString = [[NSMutableString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
currentElement = dicString;
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"title"])
{
titleString = currentElement;
NSLog(@"%@", titleString);
}
if ([elementName isEqualToString:@"description"])
{
descriptionString = currentElement;
NSLog(@"%@", descriptionString);
}
if ([elementName isEqualToString:@"link"])
{
linkString = currentElement;
NSLog(@"%@", linkString);
NSLog(@" ------------------------ ");
}
if ([elementName isEqualToString:@"guid"])
{
guidString = currentElement;
NSLog(@"%@", guidString);
}
currentElement = nil;
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
NSLog(@"Paser Error = %@", parseError);
//TODO: Create Alert message error
}
但是我想知道如何将上面的这些值(标题、描述、链接和 guid)放入 NSDictionary 中,然后将该字典放入数组中...这可能吗?这就是我的输出当前的样子
2011-12-21 16:08:08.645 NSCacheTest[15019:207] CBR Previews
2011-12-21 16:08:08.646 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.646 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.647 NSCacheTest[15019:207] Preview: Supergirl
2011-12-21 16:08:08.647 NSCacheTest[15019:207] Trapped and powerless aboard a space station, Supergirl is at the mercy of an ingenious new foe who wants to learn everything there is to know about her. But Supergirl is more than just her powers, and she'll soon show this foe – and all of Earth – what's she truly capable of! Plus, more on the Girl of Steel's mysterious origin!
2011-12-21 16:08:08.647 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.647 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.647 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.648 NSCacheTest[15019:207] Preview: Red Hood and the Outlaws
2011-12-21 16:08:08.648 NSCacheTest[15019:207] The man who has pursued Starfire all the way to the wilds of Colorado has only one thing on his mind: her slow and painful death. His name is Crux – and he's done some dark and dangerous work on his DNA to reach his goal of ridding the Earth of every alien on the planet! And Kori's about to learn that Red Hood and Roy Harper have their hands full with the ancient evil known as The Untitled!
2011-12-21 16:08:08.648 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.648 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.649 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.649 NSCacheTest[15019:207] Preview: Nightwing
2011-12-21 16:08:08.649 NSCacheTest[15019:207] As Haly's continues to travel the east coast, Dick's search for answers take him – and the circus – to Miami! But when a case from Gotham City brings Barbara Gordon to Florida, Nightwing and Batgirl must work together to bring a thief to justice. Be here as Nightwing and Batgirl tackle South Beach – and discover the true nature of the circus! The answers start this issue!
2011-12-21 16:08:08.650 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.650 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.650 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.650 NSCacheTest[15019:207] Preview: Legion of Super-Heroes
2011-12-21 16:08:08.651 NSCacheTest[15019:207] With time running out for the Legionnaire in the hands of the Dominators, it's down to Cosmic Boy to crack the riddle of how the all-powerful Daxamite Renegade made it through an impenetrable blockade… and why would Element Lad leave Chemical Kid alone in a room with that same very, very angry Renegade?
2011-12-21 16:08:08.651 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.651 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.652 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.653 NSCacheTest[15019:207] Preview: Justice League
2011-12-21 16:08:08.653 NSCacheTest[15019:207] The superstar team of Geoff Johns and Jim Lee continue the origin of the Justice League as The World's Greatest Heroes face the might of Apokolips – and find aid in an unlikely hero, as Cyborg is created!
Plus, Andy Kubert returns an amazing variant cover – his first new work after the smash-hit FLASHPOINT!
2011-12-21 16:08:08.654 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.654 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.655 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.656 NSCacheTest[15019:207] Preview: Green Lantern Corps
2011-12-21 16:08:08.656 NSCacheTest[15019:207] John Stewart has gone from being a Green Lantern soldier to prisoner of war! And in the process, he learns who the Corps' mysterious enemy truly is and what they really want. The truth will rock the Corps to its foundation!
2011-12-21 16:08:08.657 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.657 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.658 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.659 NSCacheTest[15019:207] Preview: DC Universe Presents
2011-12-21 16:08:08.659 NSCacheTest[15019:207] Step right up, step right up! Watch as Deadman plays "20 Questions" with the enigmatic Son of the Morning on a roller coaster ride like no other! Plus: Ever wonder why good things happen to bad people? Why banks put Braille writing on drive-through ATMs? And just what exactly is the nature of your relationship with God? Then you must read DC UNIVERSE PRESENTS #4!
2011-12-21 16:08:08.660 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.661 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.661 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.662 NSCacheTest[15019:207] Preview: Catwoman
2011-12-21 16:08:08.662 NSCacheTest[15019:207] Catwoman says goodbye to an old friend, says hello to an older one, and resolves more firmly than ever to strike out on her own. Only one of those things almost gets her killed.
2011-12-21 16:08:08.663 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.663 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.663 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.664 NSCacheTest[15019:207] Preview: Captain Atom
2011-12-21 16:08:08.666 NSCacheTest[15019:207] Before he received his godlike powers, Captain Atom was a military man – an Air Force pilot. Now, he's being recruited again to serve his country as only he can. But will Captain Atom go along with his new role as a weapon of mass destruction?
2011-12-21 16:08:08.666 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.666 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.667 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.667 NSCacheTest[15019:207] Preview: Birds of Prey
2011-12-21 16:08:08.667 NSCacheTest[15019:207] The only thing worse than a bomb on a speeding train is three bombs. Hidden inside the skulls of three different people. All on the same speeding train. And the Birds of Prey – Black Canary, Starling, Katana and Poison Ivy – know the names of only two of these walking bombs. Don't miss the shocking revelation that will rewrite the rules of the team forever! Yes, we know it's only issue #4! Guest starring Batgirl!
2011-12-21 16:08:08.670 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.670 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.670 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.670 NSCacheTest[15019:207] Preview: Batman
2011-12-21 16:08:08.671 NSCacheTest[15019:207] Shocking discoveries lead Batman deeper into the mystery of the Court of Owls and its secret and bloody ties to both Gotham City and the Wayne family. But an even deadlier threat awaits Batman: a trap set hundreds of years ago, far beneath his city. The war for Gotham's soul begins here!
2011-12-21 16:08:08.671 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.671 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.674 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.674 NSCacheTest[15019:207] Preview: Blue Beetle
2011-12-21 16:08:08.674 NSCacheTest[15019:207] What is Jaime Reyes going to do? La Dama and the unstoppable, mechanical monster known as Silverback both want the scarab for their own nefarious purposes, and Jaime's family and friends want to know why he disappeared. Can he keep his secret safe, or will he risk everything to tell his loved ones the truth?
2011-12-21 16:08:08.674 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.675 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.675 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.675 NSCacheTest[15019:207] Preview: Daken: Dark Wolverine
2011-12-21 16:08:08.675 NSCacheTest[15019:207] • The Kingpin of L.A. revealed!
• A standalone issue featuring Daken and FBI agent Donna Kiel
• Can Daken be redeemed?
2011-12-21 16:08:08.676 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.676 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.676 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.677 NSCacheTest[15019:207] Preview: Secret Avengers
2011-12-21 16:08:08.677 NSCacheTest[15019:207] Critically acclaimed writer Rick Remender kicks his explosive run on Secret Avengers in style in Secret Avengers #21.1! Joined by superstar artist Patrick Zircher, Remender sends Captain America’s covert strike force into the belly of the beast as he and Hawkeye uncover a huge threat to the Marvel Universe. The two must break into Red Light Nation, a country run by criminals FOR criminals, to stop an evil plot from breaching the border…headed up by an all-new Masters of Evil?! No fan can miss this perfect jumping on point as Remender and Zircher take the Secret Avengers on action packed thrill ride uncovering the dark underbelly of the Marvel Universe. It all begins next month in Secret Avengers #21.1!
2011-12-21 16:08:08.677 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.677 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.678 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.678 NSCacheTest[15019:207] Preview: Courtney Crumrin and the Night Things Special Edition
2011-12-21 16:08:08.678 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.678 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.679 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.679 NSCacheTest[15019:207] Preview: Batman: Odyssey
2011-12-21 16:08:08.680 NSCacheTest[15019:207] Batman has sidestepped death time and time again, but that all ends in this issue with the gut-wrenching reality of the Underworld. It's a surreal – yet all too real – voyage into a personal hell of his own. Batman will never be the same.
2011-12-21 16:08:08.680 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.680 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.681 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.681 NSCacheTest[15019:207] Preview: Sonic Universe
2011-12-21 16:08:08.681 NSCacheTest[15019:207] “Babylon” Part Three: The Babylon Rogues and the Battle Bird Armada – united?! And why is this fowl allegiance moving in to attack New Mobotropolis when they’re really searching for the fabled Babylon Garden? The skies erupt in battle as Sonic and Jet finally have their rematch! The surprises keep coming right through to the shocking final assault!
2011-12-21 16:08:08.681 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.682 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.682 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.682 NSCacheTest[15019:207] Preview: Conan the Barbarian
2011-12-21 16:08:08.682 NSCacheTest[15019:207] In this sweeping adaptation of Robert E. Howard’s fan-favorite “Queen of the Black Coast,” Conan turns his back on the civilized world and takes to the high seas alongside the pirate queen Bêlit, setting the stage for an epic of romance, terror, and swashbuckling. This is Conan as you’ve never seen him, with the combination of one of Robert E. Howard’s greatest tales and the most dynamic creative team in comics!
<li>A perfect jumping-on point for new readers!<br><li>A bold, fresh take on the Cimmerian.<br><li>“Queen of the Black Coast” is the most-requested Conan adaptation!</li>
2011-12-21 16:08:08.683 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.683 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.683 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.683 NSCacheTest[15019:207] Preview: Xenoholics
2011-12-21 16:08:08.683 NSCacheTest[15019:207] "ALIEN GONE WILD!"
It's an all out war between the Men in White and the Grey Aliens for possession of the Xenoholics! As our heroes continue on the run, they start to uncover the truth about their abductions. Secrets are revealed as this hot new series continues!
2011-12-21 16:08:08.684 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.684 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.684 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.684 NSCacheTest[15019:207] Preview: Strange Girl Omnibus HC
2011-12-21 16:08:08.685 NSCacheTest[15019:207] FOR THE FIRST TIME, IN ONE VOLUME: RICK REMENDER'S CRITICALLY ACCLAIMED INDIE HIT, FROM START TO FINISH! Ten years after the Rapture, a beautiful occultist and her pet demon embark on a road trip to the last open gateway to heaven, in hopes of befriending God and escaping hell on earth. A bare-knuckle, action-driven series, peppered with social commentary and dark humor, STRANGE GIRL is a story about the bewildering nature of religion, what would happen if the dark future predicted by many came true, and what a good person would endure for not having faith in advance of it. Featuring story and art by a handful of today's hottest new talents including RICK REMENDER (Uncanny X-Force, Venom), ERIC NGUYEN (Halo, Sandman), JEROME OPENA (Uncanny X-Force, Punisher) and NICK STAKAL (Criminal Macabre). Collects STRANGE GIRL #1-18
2011-12-21 16:08:08.685 NSCacheTest[15019:207] (null)
2011-12-21 16:08:08.685 NSCacheTest[15019:207] ------------------------
2011-12-21 16:08:08.685 NSCacheTest[15019:207] (null)
最佳答案
I dont know how to get the values (title, description, pubDate etc into the dictionary??)
您应该做的第一件事是阅读 Event-Driven XML Programming Guide ,特别是 Handling XML Elements and Attributes 部分(但请阅读整个文档)。该部分解释了如何处理解析不同元素并存储结果数据。
在您的特定情况下,您有一个 -parser:didEndElement:...
方法,其中包含以下内容:
if ([elementName isEqualToString:@"title"])
{
[valueDictionary ad....//I
}
这是正确的想法。您实际上只需要阅读 NSMutableDictionary 即可完成条件正文:
if ([elementName isEqualToString:@"title"])
{
[self.valueDictionary setObject:self.titleString forKey:@"title"];
}
管理同一件事的另一种方法是等到整个 item
元素结束,然后立即将所有相关值添加到字典中,然后将字典添加到 item 数组中:
if ([elementName isEqualToString:@"item"])
{
[self.valueDictionary setObject:self.titleString forKey:@"title"];
[self.valueDictionary setObject:self.descriptionString forKey:@"desc"];
// ...and so on...
[self.itemArray addObject:self.valueDictionary];
self.valueDictionary = nil;
self.titleString = nil;
self.descriptionString = nil;
// ...and so on...
}
在处理当前项目结束时将所有属性设置为 nil 是可选的 - 无论如何,您都会在下一个项目开始时分配一些新值 - 但这似乎是很好的内务管理。
另外,请注意,在我的示例中,我使用的是属性(即 self.valueDictionary
而不是 valueDictionary
)。如果您不厌其烦地创建属性,则应该使用它们——它将避免将来出现内存管理问题。
关于iphone - 如何使用 nsxmlparser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8584150/
如果我使用 NSUserDefaults 存储应用程序的设置,是否有任何方法可以使我的应用程序的设置“隐藏”,以免显示在 iPhone 上的常规设置应用程序中?我知道还有其他工具,例如 mySetti
我按照该网站的教程进行操作: http://theappleblog.com/2008/08/04/tutorial-build-a-simple-rss-reader-for-iphone/ 为了制
我通过 localisableString 和仅适用于 NSLocale 方法的不同 xib 更改 iPhone 的语言来完成本地化,但应用程序的要求是通过更改应用程序设置 View 中的语言来本地化
我试图弄清楚 iPhone 是否可以通过无线或蓝牙连接到另一台非 iPhone 设备,但发现了相互冲突的信息。我发现的大部分内容都是在 SDK 3.0 版本发布之前发现的,当时这肯定是不可能的。查看堆
This question already has answers here: Closed 7 years ago. Possible Duplicate: How to detect iPhone
当我在模拟器上运行我的应用程序时,每次都会生成白色的空白屏幕。但是当我在底部黑色 iPhone 按钮退出应用程序后,重新进入应用程序后 View 将可见。然后应用程序照常运行。 但是当我将它加载到我的
我的意思是两台 iPhone 设备应该通过蓝牙或 WiFi 连接,并且一台设备的 UI 应该扩展到另一台 iPhone 设备(不共享屏幕)。我们有办法在 iOS 中执行此操作吗? 最佳答案 Bump
如何通过宏检测设备型号?我使用过类似的东西,但模拟器上的结果总是 IS_IPHONE_5 #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInt
我目前有一个应用程序要求用户维护 VPN 隧道。加载时我检查 VPN 隧道是否可用。 我想知道是否有任何方法可以显示 UIAlertView,单击“确定”后,用户将进入 iPhone 主设置屏幕,以便
我正在开发一个 iPhone 客户端应用程序,它允许用户对各种服务进行评分。无需注册或登录。 要求是用户不能重复对服务进行评分(尽管可以更改其评分)。从目前的情况来看,该应用程序可以被删除、重新安装,
比如说,我点击一个 iphone 应用程序图标,启动时它将创建一个 .app 文件。那么是否可以从该应用程序调用另一个 iphone 应用程序。或者我们可以在该 .app 文件中执行一些操作,例如它将
真的有可能让iPhone静音模式独立于iPhone App吗? 这个应用程序"Talking Carl"让我很困惑。我的 iPhone 处于静音模式。每当我打开这个应用程序时。应用程序声音处于开启模式
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
如果我想编写一些自定义 iPhone 应用程序,但不一定通过 App Store 分发它们,是否可以在不加入 iPhone 开发者计划的情况下实现? 假设我只是想为自己编写一些小实用程序并将其放入我的
人们对 Unity 或 Torque Engine 等游戏引擎有何看法和/或体验?如果您是 iPhone 游戏开发新手,是否值得学习其中一种引擎?这些引擎生成的应用程序与使用 sdk 的 native
您能否在未安装 XCode 开发工具的计算机上分发 iPhone 应用程序以在 iPhone 模拟器中进行测试?可以直接在电脑上安装模拟器进行测试吗? 我有一组测试人员,他们不是开发人员,除了能够运行
我想在我的越狱设备上构建并安装我的应用程序,而无需支付 iPhone 开发者计划所需的 99 美元。我有 Rock 和 Cydia...最简单的方法是什么(如果可能的话)? 谢谢。 最佳答案 这是一个
我想测试一个网站,看看它如何与 iPhone 配合使用,但我没有 iPhone 或 iPod touch。有没有一种方法可以让我在不拥有网站的情况下测试网站的运行情况? 我真正想要的是修复 Stack
简单地说;我的 99 美元能给我带来什么我无法免费获得的东西? 好吧,好吧,听起来是个愚蠢的问题,但苹果网站对我来说并不清楚。 我的预感是,您可以在 99 岁时向应用程序商店提交应用程序,但您可以免费
我是一名注册的 iOS 开发人员。如何将我的 iPhone 应用程序转移到我的个人 iPhone? 最佳答案 用于测试?只需选择您的设备而不是模拟器即可。 关于iphone - 如何将我的 iPhon
我是一名优秀的程序员,十分优秀!