I'm developping an app which get data from a web xml file. I'm basically following this reference, but with the function
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
because the xml from the web has the following structure:
<?xml version="1.0" encoding="iso-8859-1"?>
<lista>
<elemento>
<id><![CDATA[1468]]></id>
<tipo><![CDATA[1]]></tipo>
<fecha><![CDATA[01/09/2011]]></fecha&开发者_如何学编程gt;
<evento><![CDATA[Rodrigo]]></evento>
<descripcion><![CDATA[La selección musical de Rodrigo no deja de sorprendernos. Desde el soul y el funk a los ritmos más bailongos este Dj's hace saltar las chispas de todos aquellos que tienen el placer de escucharlo, si todavía no lo has disfrutado no lo dudes acude los jueves y disfrútalo en directo, es como los polos Colaget, enganchan.]]></descripcion>
<flyer><![CDATA[mad_sep11.jpg]]></flyer>
</elemento>
</lista>
Well, usually this is working correctly, and I can get the "id", "tipo", and "fecha" data withouth problems, but the "evento" an "descripcion" info is null. After trying to debug this problem I realise that the "parser founCDATA" function only get the blocks from the others tags (even the last one "flyer" tag), and i have no idea why is that.
Here is my "parser founCDATA" function:
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
NSLog(@"CDATABLOCK %@", CDATABlock);
NSString *textWithBlanks = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
currentStringValue = [[NSMutableString alloc] initWithCapacity:50];
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet];
[currentStringValue appendString:[textWithBlanks stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
NSLog(@"CURRENT STRING %@", currentStringValue);
}
And here is the output of that function after the parsing:
2011-09-26 12:29:55.188 project[462:707] CDATABLOCK <31343638>
2011-09-26 12:29:55.192 project[462:707] CURRENT STRING 1468
2011-09-26 12:29:55.196 project[462:707] CDATABLOCK <31>
2011-09-26 12:29:55.199 project[462:707] CURRENT STRING 1
2011-09-26 12:29:55.202 project[462:707] CDATABLOCK <30312f30 392f3230 3131>
2011-09-26 12:29:55.206 project[462:707] CURRENT STRING 01/09/2011
2011-09-26 12:29:55.218 project[462:707] CDATABLOCK <6d61645f 73657031 312e6a70 67>
2011-09-26 12:29:55.221 project[462:707] CURRENT STRING mad_sep11.jpg
As you could see, it works perfectly for 3 of the tags, but not for the "evento" and "descripcion" where the the function is even not running at all, and i have no idea of the reason.
Any ideas???
Sorry for such an specific question and thanks for everyone.
Yandrako
精彩评论