- 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/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!