views:

1051

answers:

3

I'm having strange problems parsing (apparently) correct XML code!

The xml parsed is:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
<results>
<file id="0" name="   Linux Ubuntu.rar                                                                  700.64     2" size="700" disp="2"/>
<file id="1" name="   [Soft] Sistema operativo Linux. Live CD Distro Ubuntu-5.04-live-i386.iso          624.926     4" size="5" disp="4"/>
<file id="2" name="   ubuntu-9.04-server-i386.iso                                                       577.220     2" size="9" disp="2"/>
<file id="3" name="   virtualbox-3.1_3.1.2-56127_Ubuntu_karmic_amd64.deb                                 43.578     1" size="3" disp="1"/>
<file id="4" name="   [APP-ITA].UBUNTU.LINUX.iso                                                        586.822     2" size="586" disp="2"/>
<file id="5" name="   Ubuntu linux 2007.iso                                                             700.446     1" size="700" disp="1"/>
<file id="6" name="   Installare aMule Adunanza + Liste Server + Liste Nodi su Ubuntu Gutsy [Fastweb      0.72     5" size="0" disp="5"/>
<file id="7" name="   - Guida Per Linux Ubuntu 7.03 Facile Da Usare!!!!!!!La Prima In Ita.rar           731.351     3" size="7" disp="3"/>
<file id="8" name="   Ubuntu Hacks - Tips and Tools for Exploring, Using, and Tuning Linux (O'Reilly,     3.494     1" size="3" disp="1"/>
<file id="9" name="   Linux-ubuntu-8.04.1-desktop-i386.iso                                              694.498     3" size="8" disp="3"/>
<file id="10" name="   [MANUALE] Ubuntu Linux - Computer Magazine.pdf                                     86.992     2" size="86" disp="2"/>
<file id="11" name="   (Ebook - Ita - Software) Ubuntu - Desktop Guide.pdf                                 0.686     3" size="0" disp="3"/>
<file id="12" name="   Installare Amule Adunanza In Ubuntu.rar                                             0.25     6" size="0" disp="6"/>
<file id="13" name="   UBUNTU LINUX [ITA].PDF                                                              0.536     62" size="0" disp="62"/>
<file id="14" name="   Comandi Fondamentali Ubuntu.rtf                                                     0.67     4" size="0" disp="4"/>
<file id="15" name="   ubuntu Guida.tar                                                                    0.160     1" size="0" disp="1"/>
<file id="16" name="   ubuntu-remix-italiano-8.10.iso                                                    702.720     1" size="8" disp="1"/>
</results>
</root>

NSXMLParser gives me the following error:

2010-01-13 20:23:22.500 iMule[1419:20b] Error 65, Description: (null), Line: 13, Column: 24
2010-01-13 20:23:22.516 iMule[1419:20b] Error 4, Description: (null), Line: 1, Column: 1

The funny thing is that, if i parse these lines singularly i have no problems, the parser dosent fuss at all!

My parsing code is:

    // DELEGATE XML PARSER

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName     namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName   attributes:(NSDictionary *)attributeDict{
    if([elementName isEqualToString:@"downloads"] || [elementName isEqualToString:@"results"]){
    NSLog(@"starting or downloads or results");
    if(xmlArray){
        xmlArray= nil;
    }
    self.xmlArray= [[NSMutableArray alloc] init];
    if([elementName isEqualToString:@"results"]){
        [self.results_controller.activity startAnimating];
    }
    if([elementName isEqualToString:@"downloads"]){
        [self.downloads_Controller.activity startAnimating];
    }
}
else if([elementName isEqualToString:@"file"]){
    NSLog(@"found file...");
    [self.xmlArray addObject:attributeDict];
}
}

 - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(elementName);
if([elementName isEqualToString:@"downloads"] || [elementName isEqualToString:@"results"]){
    if([elementName isEqualToString:@"downloads"]){
        NSLog(@"downloads found...  reloading table");
        self.downloads_Controller.downloads= xmlArray;
        [self.downloads_Controller.tableView reloadData];
        [self.downloads_Controller.activity stopAnimating];
    }
    else if([elementName isEqualToString:@"results"]){
        NSLog(@"results found... reloading table");
        self.results_controller.results= xmlArray;
//          NSLog(@"xmlarray: %@ and results: %@", xmlArray, self.results_controller.results);
        [self.results_controller.tableView reloadData];
        [self.results_controller.activity stopAnimating];
    }
}
else if([elementName isEqualToString:@"error"]){
    UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"Error" message:@"aMule dosent seem to be on" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
}
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
NSLog(@"Error %i, Description: %@, Line: %i, Column: %i", [parseError code],
      [[parser parserError] localizedDescription], [parser lineNumber],
      [parser columnNumber]);
 }

- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError *)validError{
NSLog(@"valid: %@", validError);
}


// END DELEGATES XML PARSER

Does someone have a clue of what it could be?

Thanks

A: 

The apostrophe in O'Reilly?

MJB
Tried, it's not an escape char, as i removed them all
PirosB3
+1  A: 
Dewayne Christensen
No actually the data is parsed from the socket,socket --> NSData --> NSXmlparser.i'll add the parsing code
PirosB3
If i parse the same xml in python i have no problems at all, everything is displayed properly! :(Could it be that the parser has problems parsing so much data at once? and the funny thing is that, after searching for something else, so different xml, it gives the error always in the same place!! :(Any suggestions?
PirosB3
works perfect now.. thanks
PirosB3
A: 

Did you look up the error codes?

Looks like the XML parser thinks some space is required at the 24th column of the 13th line.

Could you post the XML data on a pastebin so we can look at the raw data? I suspect that either you or Stack Overflow changed the data in some way (perhaps for formatting reasons) and this threw off the line/column numbers from what NSXMLParser is reporting.

Peter Hosey
Thanks for your help.Usually it gives me error 40 and 4... but strangely enough i made the same program in python and data gets parsed perfectly! :( could it be a buffer problem?Search for "Ubuntu"http://pastebin.com/m7667fea0Error:2010-01-16 13:32:25.137 iMule[867:20b] Error 40, Description: (null), Line: 34, Column: 70
PirosB3
Please edit the question to include the method that instantiates the NSXMLParser. And, again, you should look up any error codes you get from NSXMLParser in the documentation: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/doc/constant_group/Parser_Error_Constants
Peter Hosey