views:

584

answers:

5

Hi.

i noticed strange problem in sdk 3.0. When i parse XML everything works fine in any sdk 2.x but sdk 3.0 doesn't it.

I didn't find any difference in NSXMLParser but any 2.x sdk works fine and 3.0 doesn't. If anybody met such problem and tell me how to u solve it? -> rssParser is NSXmlParser object.

In sdk 3.0

i call this method.[rssParser parse];

then the first method my parser called is this

  • (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError

and after that it does nothing.

when i select sdk 2.2.1

then also it calls this method

  • (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError

but parser doesn't stop parsing it continue with calling other delegates of NSXmlParser.

Parse error is same in both

Error 65,Description: (null), Line: 1, Column: 60

This is the first line

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" with < > on both end

+3  A: 

Well, you are trying to parse a HTML file with NSXMLParser. An NSXMLParser needs a valid XML file and HTML files aren't valid XML files, they could be, but almost all are not. The doctype for instance isn't valid XML. Your using the wrong "tool" for the job.

The reason why it doesn't work on 3.x, but does on 2.x is not known to me, looks like there has been a change in behaviour after all.

I'd suggest using libxml2 to parse the HTML file and not NSXMLParser. Libxml2 can be used to parse "real world" HTML.

You might want to look at this StackOverflow topic:
http://stackoverflow.com/questions/405749/parsing-html-on-the-iphone/406111#406111

Yannick Compernol
A: 

It sounds like there's an error in your xml that the 2.x parser could get past but the 3.0 parser is more strict and stops.

Can you post the smallest xml you can make that causes this error?

Sam

deanWombourne
A: 

i m also getting same problem.have u got solution for it?????

aisha
See accepted answer...
Vladimir
A: 

My xml file contains an error

after removing , the problem is solved. i dont know why it was working fine for NSXMLParser in OS 2.2.1.May be that ignore error in xml file.

aisha
+1  A: 

Actually the problem is that in 3.0 NSXmlparser is more restrict and it will not parse any file in 3.0 which contain any error.Answer given by Yannick Compernol is correct.to sove the problem I used libxml2.You can see this link to get the code for the parsing

http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html

vikas