NSXmlParser doesn't work in iphone sdk 3.0 - iphone

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

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:
parsing HTML on the iPhone

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

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

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.

Related

How parse html string in iphone

i m using php file for using data in my application,
in this file i post data on the server and if i get the data from the server
then it is in html formate.
so problem is that i have a string with html tags how i use data in that string.
how i extract data from html string.
Use NSXMLParser class. it works for HTML too. There are three useful delegate methods.
If your HTML out put is some simple data - may be you can write some simple NSString parser your self like 'markhunte' mentioned, if you have large complex data in HTML then you have to go for some open source parsers.
Cocoa does not provide HTML parser, Forum discussion claims in some case XML parser itself work for you, but I never go it working for my data.
In my case I had very simple TAG which I had handled using my own parser using NSString.
I have used the code from --> Flatten-html-content-ie-strip-tags-cocoaobjective-c.
There are also examples of its use on SO.
Just use NSScanner, it is great for searching in between tags that are permanent. If you post some page code I help you set up the scanner.

Building libxslt for iPhone

I just had an app rejected for linking to libxslt using this technique.
I'd really like to use XSLT in my app, so it looks like my only shot is to compile it myself. I don't want to use a UIWebView because I want to store the resulting HTML, not just display it.
Has anyone done this -- compiled libxslt for the iPhone?
After some Googling, I've got an old Xcode solution from here and git-cloned the latest libxslt from gnome.org. Neither approach has worked out so far (autoconf bails out, and the Xcode project is missing a bunch of files).
Any advice would be appreciated.
Thanks!
Update 7/21
I found a workaround by giving UIWebView some XML linked to an XSL stylesheet. After the data loads,
I can grab the transformed HTML like this (source):
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
html = [webView stringByEvaluatingJavaScriptFromString:
#"document.documentElement.outerHTML;"];
}
That said, if anyone has any hints on using libxslt directly, I'd love to hear them. Dropping into javascript seems so...unsavory.
You're not allowed to add dylibs, but you can link to a .a file. Can you get the configure for libxslt to output a .a file instead?

Tutorial or sample code for parsing xml file using libxml2 in IPhone Application

I just want a tutorial demonstrating the parsing of XML File using libXml2 in Iphone . I found tutorials on TouchXMLand other but not the same for Libxml2
Please help if u can.
Apple has an example iPhone project that parses some simple XML using both NSXMLParser and libxml2 SAX2. You can find the project here:
http://developer.apple.com/iphone/library/samplecode/XMLPerformance/Introduction/Intro.html
Although this isn't exactly a tutorial, it is working code. It runs in the simulator out of the box. Because it accomplishes the same task twice, you should be able to compare the libxml2 code to the NSXMLParser code to figure out what's going on.
Not even these?
I recommend TBXML. I use it everytime I need to parse a XML File. It's really easy to use. ;-)
See here: TBXML Homepage
A good sample is:
http://bill.dudney.net/roller/objc/entry/libxml2_push_parsing

NSXMLParser Error

I am using NSXMLParser to parse the html file on the server side.(using iphone sdk 3.0)
and my parser stop parsing after it encounter any error and call the delegate message
(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
My Ques:How can I parse the file after it encounter the error.Is there any way to do so.
Thanks
You can't. Parsing is stopped when the error is encountered. It would be hard to know what the rest of an erroneous XML document meant, anyway, as the meaning of anything at one location in the document depends on everything that came before it (in this case, including an error).
You're looking for a different kind of parser. An "at-all-costs" parser would be able to do what you want. If you are getting XML from lots of different sources this is ideal.
If you have a few sources you can workaround their problems. For instance, if the only issue you get is that they told you it was UTF-8 when it turns out it is ISO-8859-1 you could run through it once, find out it fails due to a character issue, convert the XML from ISO-8859-1 to UTF-8 and try again. Since you know where the error was you can try to make some sort of fix. It's quite expensive to go this route though.

iphone sdk - XML parseErrorOccurred: how to get rid of the illegal charaters when parsing in XML?

When pasrsing XML using NSXMLParser, I encountered this problem when the parser received some characters that it couldn't take such as: the auto-correct "..." or "--" in MSWord.
My app reads XML which is exported out of my database from a PHP file. I wonder if I should handle this on the server side or on the iPhone SDK and How?
any help would be appreciated.
It sounds like an encoding issue.
Are you sure that the XML file is being served as the same encoding as in its header?