Image URL from an XML - ios

Hi i am parsing an Xml and gets the data in NSSTring from the description tag as follows.
NSString *Descree= [eleme.description stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#" \n\t"]];
NSLog(#"Here- %#",Descree);
i find the following result in console.
<span style="float:left"><img src="http://www.thtfjhj.net/contents/albumsth/57.jpg" /></span><p ><b></b></p>
From this I need to extract the image URL alone.
http://www.thtfjhj.net/contents/albumsth/57.jpg

Your xml contains html content within.
So it would be better if u use html parsing, to extract the required fields.
Here is a great tutorial to do it.
If the html contains multiple img tags, you can fetch each contents using html parsing.

plz use NSXMLParser to parse xml data

Related

How to parse the media:group tag in the rss feed in iOS?

I tried to parse the "media:group" tag manually or via FeedKit swift. But getting the nil response for this. Please let me know how to parse this tag.
This is url of rss feed http://www.rollingstone.com/music/rss and format is like this
<media:group>
<media:content url="http://img.wennermedia.com/featured/rs-jb-5db24d0d-72d6-4f17-b7b8-0aa192b13dc3.jpg"/>
<media:content url="http://img.wennermedia.com/article-leads-vertical/rs-jb-5db24d0d-72d6-4f17-b7b8-0aa192b13dc3.jpg"/>
<media:thumbnail url="http://img.wennermedia.com/reading-list/rs-jb-5db24d0d-72d6-4f17-b7b8-0aa192b13dc3.jpg"/>
</media:group>
media is namespace in xml language, tag name will be group.
If it's important to know tag namespace, then you should enable shouldProcessNamespaces and shouldReportNamespacePrefixes in NSXMLParser.

Simple NSData's category to parse XML with cyrillic

I have to parse NSData with XML string, does somebody know simple category to do it? I have such for JSON, but I forced to use XML. I tried to use XMLReader, it's interface looks clean, but I found some issues:
Mysterious new line characters and spaces everywhere:
"comment_count" = {text = "\n \n 21";};
My cyrillic symbols looks so:
"description_text" = {text = "\n \U041f\U0438\U043a\U0430\U0431\U0443\U0448};
Example:
<?xml version="1.0" encoding="UTF-8" ?>
<news>
<xml_count>43</xml_count>
<hot_count>449</hot_count>
<item type="text">
<id>1469845</id>
<rating>147</rating>
<pluses>171</pluses>
<minuses>24</minuses>
<title>
<![CDATA[Обновление огромного архива Пикабу!]]>
</title>
<comment_count>26</comment_count>
<comment_link>http://pikabu.ru/story/obnovlenie_ogromnogo_arkhiva_pikabu_1469845</comment_link>
<author>icq677555</author>
<description_text>
<![CDATA[Пикабушники, я обновил свой огромный архив текстовых постов из горячего!]]>
</description_text>
</item>
</news>
I just realized whats' going on. Your data samples are obviously NSDictionary instances printed in the debugger. So the issues you found are:
As XML was originally designed as an annotated text format, the whitespace (spaces, newlines) handling doesn't perfectly fit for data only usage. You can either trim all resulting strings ([stringVar stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]), adapt XMLReader to do it or use the XML parser at http://ios.biomsoft.com/2011/09/11/simple-xml-to-nsdictionary-converter/ (which does it by default).
The funny output you get for Cyrillic characters is the proper escaping for non-ASCII characters in the debugger output (which uses the old-style property list format). It's an artifact of the debugger output. Your variables contain the proper characters.
BTW: While JSON contains implicit type information (strings are always quoted, numbers are never quoted etc.), XML without a schema file does not. So all the parsed simple values will be strings even if they originally were numbers.
Update:
The XML parser you're using still contains the old whitespace handling code described in Pesky new lines and whitespace in XML reader class (though the comment tells otherwise). Apply the fix mentioned at the bottom of the answer, namely change the line:
[dictInProgress setObject:textInProgress forKey:kXMLReaderTextNodeKey];
to:
[dictInProgress setObject:[textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:kXMLReaderTextNodeKey];

retrieve xml file using nsxmlparser in ios

i am getting problem while reading xml files through nsxmlparser in ios,
<PRODUCTS>
<PRODUCTSLIST>
<PRODUCTDETAILS>
<headertext> test header </headertext>
<description><b style="font-size: x-small;">product, advantages</b></description>
</PRODUCTDETAILS>
</PRODUCTSLIST>
</PRODUCTS>
while i read the file using nsxmlparser i am able to get value(test header) for headertext but the description attribute value contains html tags so i cant able to get the result (<b style="font-size: x-small;">product, advantages</b>)i am getting result as empty
How can i get the result as((<b style="font-size: x-small;">product, advantages</b>)) for description attribute?
Speaking from a developers perspective I would not recommend using NSXMLParser due to it's laborious way to parse XML Files. There is a great write up about choosing the right XML Parser.
I use KissXML quite often.
You can find a quit tutorial of using it here.
Hope this helps.
Your problem is that the "b" tag is considered part of the XML structure, try escaping the '<' and '>' characters of the 'b' tag:
#"<b style=\"font-size: x-small;>product, advantages</b>"
see here

How to read .html file to Xcode UI

I'm doing the task of changing the rtf files to html files. However,how to read .html files to NSTextView or other Object.I test the following API works well in reading HTML file.
NSTextView *showHtml;
[showHtml readRTFDFromFile:[[NSBundle mainBundle] pathForResource:#"test" ofType:#"html"]];
The object showHtml can shows Html files as the browse does.
But The API readRTFDFromFile descript like that only read rtf or rtfd files.
Are there any API or method to shows Html file in xib.
I also test the API:
[[NSAttributedString alloc] initWithHTML:(NSData *) data documentAttributes:(NSDictionary **) docAttributes],
setAttributedStringValue:(NSAttributedString *) aAttributeString
But It can't shows the attribution except the string .
Thanks for your reply.

iphone image caching from initWithString in webview

i am parsing json from SBJson parser. I am using SDWebIamge for image caching. My JSON data has one tag namely "content" which has text + image links in between text. Just for example something like this
<p>This is sample text.<\/p>\n<p><a href=\"http:\/\/xyz.com\/08\/15.jpg\"><img class=\"aligncenter size-full wp-image-1273\" title=\"15\" src=\"http:\/\/xyz.com\/08\/15.jpg\" alt=\"\" width=\"422\" height=\"720\" \/><\/a><\/p>\n<p><a href=\"http:\/\/xyz.com\/08\/16.jpg\"><img class=\"aligncenter size-full wp-image-1274\" title=\"16\" src=\"http:\/\/xyz.com\/08\/16.jpg\" alt=\"\" width=\"680\" height=\"1024\" \/><\/a><\/p>\n<p> <\/p>\n
which i parse and store in my NSString variable.Then i have a webview which i load from this NSString by
NSString *htmlString = [[NSString alloc] initWithString:myObj.Content];
which loads the text and fetches link images as well by default as we all know web view does.I am saving this JSON data to file for offline viewing which is working great thanks to SDWebimage.But my issue is when i load the save content to webview it shows only text no image cause these is no image cashing in the NSString links which i loaded.So how can i cache the images in my webview so that next time when i load my webview from string it will show images from the link in my NSString data.
Thanks
You can use an existing implementation to do this - something like ASIWebPageRequest or ProxyingUIWebView should to the trick.
Alternatively you could try to implement this yourself. One option is something like the following:
Parse the HTML string and detect any img tags and their src attributes
Download and store any images detected
Display the stored (downloaded images) in place of the online originals by modifying the path to the images in the img tags in your HTML string.
Note this is a far from optimal solution and is only an example of one possible implementation.

Resources