Parsing the xml file independent of tags - iphone

I want to parse the xml file independent of the tags .So the code for the parsing should become generic one. Is there any way to do this in iPhone which is flexible with tags. I have tried to solve this problem by parsing the xml two times.In first parse i have extracted tags only and in second pass i tried to find the value of that tag. But there was the problems with this approach . So is there any api or logic to parse xml independent of tags? is it really possible?

In iOS there is no existing API or logic for parsing xml files with unknown tags. To parse xml you need to know tags of that xml.

Related

Read Epub3 in ios app

I am learning on epub reader app. I have tried and parsed the epub 2. I found that it has a opf file which refer to toc.ncx file which is actually a xml file and I can parse it to get the content and html files. Than I can display it in UIWebView.
I tried with same approach to parse the epub 3 file. I got the .opf file and parse it but the problem is there is no .ncx file. It has toc.xhtml file. It is the index file what I needed but in xhtml format. I am not sure if all files have same format or not. If all epub3 has same format than I can created a custom HTML parser according to my requirement.
Is there any efficient epub3 reader sample available for ios? I found one here but it contains errors and there is nothing mentioned for configuring it.
Any help please.
I know of two iOS EPUB3 readers these are iBooks and Gitden reader.
EPUB3 must contain a navigation file based on HTML5
See: http://www.heliconbooks.com/article/epub3navdoc
You can simply display this file as standard HTML file, however notice that this file must contain semantic tags like
There may be more then one section in each TOC file.
This file is pointed to by the OPF file, in the manifest section there should be one and only one item with property="nav"

Objective-C Parse Html Table Content

I'm looking for detailed instructions how to parse an html table content into UITableView.
I have the data from the NSURLConnection but I need specific part of the table.
Thanks!
You may use one of the DOM XML parsers, like GData, KissXML or TouchXML +
XPath API (all 3 seems to support it) to extract your data.

Objective-C – Smart programming with dependencies

I have an iOS application that parses xml data from the web. I've setup it to parse some xml tags for me and then display some information in the application.
I do not own the xml data so it's not unlikely that the xml tags could change without my knowledge and then rendering my iOS application useless because I'm not able to parse the data with the wrong xml tags.
So instead of having the application crashing when (if) they change xml tags I was thinking of having the application send an e-mail in the background alerting that the xml tags have changed. Or something like that. Is that possible to do or is it even a smart solution to my problem?
Why don't you parse the XML file in your server side using any technology that you prefer, and provide your controlled XML file to your iOS application. That way you will have the full control over the XML tags that your application expects! If the other party changes the tags, you just re-write your server side program to handle the changes gracefully!

Best Way to Parse HTML to XML

Essentially, I currently have an iPhone app that can query and parse an XML file on my server. Right now, I currently have to manually update and upload my XML file every morning so my users can have the updated information. I would like to automate this process, which would essentially entail parsing various websites (NYTimes, iAmBored.com, etc), outputting the relevant information from each of these websites to an XML file, and uploading that file to my server.
Does anyone know the best way to accomplish this (parsing HTML to an XML file). Since I am a beginner, I'm not sure what languages this requires or what is the best way to do this?
Thanks a lot in advance!
You can try to translate HTML to XHTML (XHTML is based on XML so it's XML with some rules defined in a DTD).
You can also try to parse directly HTML with a SGML parser (As XHTML is based on XML, HTML is based on SGML).
The links are provided as inspiration.
If the content you need to scrape is in XHTML then you can easily use the XSLT language to transform original content in what you need inside the XML you provide to your users.
Otherwise any kind of scraping and XML producing solution will be fine, every programming language has its support to do such things.. but you could use XPath to select the elements you need from the page and then save them inside the output file.
Can you get what you need from the RSS/Atom feeds? That will simplify things greatly because they are XML rather than HTML and can be parsed by a standard XML parser. Of course, descriptions embedded inside RSS feeds will be HTML, so depending on your application, that may be when you need to parse HTML.
XSLT is a domain-specific programming language designed for processing XML, but you can also use any programming language that includes an XML parser for the task.
TagSoup - Just Keep On Truckin'
...a SAX-compliant parser written in Java
that, instead of parsing well-formed
or valid XML, parses HTML as it is
found in the wild: poor, nasty and
brutish, though quite often far from
short.
TagSoup is designed for people
who have to process this stuff using
some semblance of a rational
application design.
By providing a SAX
interface, it allows standard XML
tools to be applied to even the worst
HTML. TagSoup also includes a
command-line processor that reads HTML
files and can generate either clean
HTML or well-formed XML that is a
close approximation to XHTML.
Also, Taggle, a TagSoup in C++, available now

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.