Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSXMLParser不能正确处理“;_Iphone_Ios_Nsxmlparser_Symbols - Fatal编程技术网

Iphone NSXMLParser不能正确处理“;

Iphone NSXMLParser不能正确处理“;,iphone,ios,nsxmlparser,symbols,Iphone,Ios,Nsxmlparser,Symbols,我在iPhone应用程序中解析xml时遇到一些问题。下面是我想用标准的NSXMLParserparser解析的xml代码的一部分 <item> <title>AMNews: Facebook & Twitter Updates Might Lead To Burglary, Oldham School Violates DPA, Amazon Cloud “Burstsâ€</title> <link>http://www.itprop

我在iPhone应用程序中解析xml时遇到一些问题。下面是我想用标准的
NSXMLParser
parser解析的xml代码的一部分

<item>
<title>AMNews: Facebook & Twitter Updates Might Lead To Burglary, Oldham School Violates DPA, Amazon Cloud “Burstsâ€</title>
<link>http://www.itproportal.com/2011/04/22/amnews-facebook-twitter-updates-might-lead-to-burglary-oldham-school-violates-dpa-amazon-cloud-bursts/</link>
<description>People announcing their holiday plans on social networking platforms like Facebook and Twitter are putting themselves at risks from thieves and burglars. A new study ha</description>
<author>ravimandalia@itproportal.com (Ravi Mandalia)</author>
<pubDate>Fri, 22 Apr 2011 08:19:36 +0100</pubDate>
<guid>http://cdn.itproportal.com/photos/facebook-logo-4_thumb80x80.png</guid>
</item>
我试图获取标题并保存它,但我的解析器工作错误。解析器只获取“符号后的文本


我能做什么?谁能告诉我parse发生了什么?非常感谢

您能给我们展示一下您的
-parser:foundCharacters:
的实现吗?如何存储
字符串


我还曾经在XML文件中使用过带有特殊字符的
NSXMLParser
,它工作起来没有问题。

下面是
-parser:foundCharacters:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    //in case of unusable tags
    if (currentArticle == nil) {
        return;
    }
    // Get Title.   
    if ([currentElement isEqualToString:@"title"]) {
        [self.currentArticle setTheTitle:string];
    // Get Description.
    } else if ([currentElement isEqualToString:@"description"]) {
        string = [string stringByReplacingOccurrencesOfString: @"\n" withString: @"" ];
        [self.currentArticle setTheSummary:string];

    } else if ([currentElement isEqualToString:@"link"]) {
        [self.currentArticle setTheMainLink:string];

    } else if([currentElement isEqualToString:@"guid"]){
        [self.currentArticle setTheImageLink:string];

    } else if ([currentElement isEqualToString:@"pubDate"]) {
        [self.currentArticle setThePubDate:string];

    } else if([currentElement isEqualToString:@"author"]){
        [self.currentArticle  setTheAuthor:string];
    }
}
我注意到解析器第一次从开始到结束有两次获得标题,第二次从结束到结束。就像在我的提要中一样,有两个title标签

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    //in case of unusable tags
    if (currentArticle == nil) {
        return;
    }
    // Get Title.   
    if ([currentElement isEqualToString:@"title"]) {
        [self.currentArticle setTheTitle:string];
    // Get Description.
    } else if ([currentElement isEqualToString:@"description"]) {
        string = [string stringByReplacingOccurrencesOfString: @"\n" withString: @"" ];
        [self.currentArticle setTheSummary:string];

    } else if ([currentElement isEqualToString:@"link"]) {
        [self.currentArticle setTheMainLink:string];

    } else if([currentElement isEqualToString:@"guid"]){
        [self.currentArticle setTheImageLink:string];

    } else if ([currentElement isEqualToString:@"pubDate"]) {
        [self.currentArticle setThePubDate:string];

    } else if([currentElement isEqualToString:@"author"]){
        [self.currentArticle  setTheAuthor:string];
    }
}