How to get data from xml file on iOS - ios

What I did on iOS is displaying grid of 10 images. For this I take a array and add all images to array. For this I am write the code as:
[_image addImage:[UIImage ImageNamed:#"black.jpg"]];
like this I add all images to array. Now what I need is to get all the images through Xml file and add to the images array. How can I do this?

The class you need is NSXMLParser and the delegate NSXMLParserDelegate.

Have a look here or even here at SO. What you are looking for is to parse an XML document, and you can do it with the NSXMLParser class, libxml2, or other libs/tools mainly based on those two. Also you'd better have a look at this project by Apple it will show you the main differences in terms of performance between technologies

First of all you need to parse your xml file. You can use the NSXMLParser class. How exactly you would do this, depends on the structure of your xml file. There are a lot of tutorials on the Internet about how to use it, for example see here.

Related

Writing List of object into CSV File in xamarin.Android

Can any one suggest me How to implement writing List of objects into .csv into device download storage in c# xamarin android.The data exported to csv should be having headers.each item in list should be written in row .something similar to image attached
To create a CSV string, you'd generally do this manually. As an example:
string headers = $"{Column1},{Column2}";
string row1 = $"{row1.ValueA},{row1.ValueB}";
...etc...
Then append them together, separated by newlines. Obviously you'd be better off doing the above in some kind of loop.
As for putting it into android download storage, someone else will have to tell you how to do that, I don't know how!
i have followed below link http://www.joe-stevens.com/2009/08/03/generate-a-csv-from-a-generic-list-of-objects-using-reflection-and-extension-methods/ that helped me to implement.

Using JSON, display all images into UICollectionView from web directory

I'm new to iOS dev and need a UICollectionView to display all images in async within a folder on my webserver.
Let's say the folder is: www.website1.com/img/new/
I will have a JSON file that shows text and an image pertaining to that text. Something really basic like:
{"Items":[
{"URL":"URL.com/img1.jpg", "TEXT":"TEXT1"},
{"URL":"URL.com/img2.jpg", "TEXT":"TEXT2"},
{"URL":"URL.com/img3.jpg", "TEXT":"TEXT3"}]}
The code simply needs to parse the JSON and update accordingly. What would be the simplest way to achieve this?
Create object form your flux Json
Create and fill data source of your collection , this data source contain all objects
Custom your UICollectionViewCell (imageView)
Manage downloading image since CellView (use cache)
See this article for asynchrone download https://www.appcoda.com/ios-concurrency
hope it help.

ios creating multiple-page pdfs

How would I go about creating a multiple page pdf from a scrolling view? I am trying to convert an invoice pdf and it is much longer than 1 page; not sure how to create more.
also while on this, the pdf also seems to be quite choppy in quality ( very rasterized ) - any tips to improve this? i realize it's not vectorized, hence the choppy look, just looking for a way to make it better? thanks
To create multiple pdf, after creating each page you can convert the entire page to an image an store it in an array, one by one. Then you can show each image from the array as scrollview if thats what you meant.
You can create pdf pages and write it to a file with following function. Call it for each page.
-(void)savePDFImageToDocumentDirectory:(UIImage *)pdfImage withPageNumber:(int )pageNumber{
NSString *tmpPngPath = PDFTempDirectoryPath;
NSString *pageName = [NSString stringWithFormat:#"PDFPage%d.png",pageNumber];
NSString *imagePath = [tmpPngPath stringByAppendingPathComponent:pageName];
[UIImagePNGRepresentation(pdfImage) writeToFile:imagePath atomically:YES];
}
You can follow two approaches tom create pdf. One through html method and the other is from xib files. Html method is fast but pdf will be of less quality. xib method gives you high quality pdf but uses a lot of memory.
If you are happy for the PDF generation to be remote you could use a service like Docmosis cloud services or Aspose to create the Document and stream it back to the device (or email it or both etc).
Typically these PDF tools wouldn't build documents from images like screen shots - you would send the data you want populated instead. This means the quality is very good (and text is selectable etc) and multiple pages is expected making the PDFs more generally useful.
Please note I work for the company that created Docmosis.
Hope that helps.

Need assistance getting (parsing?) these JSON data into Xcode

Before I start, I would like to say that I'm quite a newbie to Xcode and the C Language, and I'm trying my best to learn as much as I can. I have researched for about 2 days now before posting this question but could not find anything helpful :( I am genuinely stuck and would appreciate ANY help. This is most likely a very simple/basic question:
Basically, I am trying to get this data (LINK) which is apparrently in UTF-8 JSON and display it on a simple label on Xcode. However, I do not know how to get that data and parse it at all. I've followed a tutorial online with success, but that deals with JSON objects rather than arrays (which I think I am dealing with).
I would HIGHLY appreciate it if someone could extract/parse the data from the first link given into a basic label on Xcode in code format.Preferably with commentary on what most lines of code are doing for my own benefit, as this would really help me understand how it works. Hopefully from there, I would be able to make good progress.
Once again this is highly appreciated!
Thank YOu.
Here's a sample of the JSON URL for convenience if you don't want to click the link:
[4,"1.0",1343920773538]
[1,"Spring Gardens","59581","275","Barkingside",1343920940000,1343920940000]
[1,"Spring Gardens","59581","275","Barkingside",1343921717000,1343921717000]
[1,"Spring Gardens","59581","549","Loughton",1343921858000,1343921858000]
[1,"Spring Gardens","59581","275","Barkingside",1343922204000,1343922204000]
[2,"Spring Gardens","59581","8a56a0ab37b72b400137cb7cfd954038_29222",0,3,"Bus routes serving this stop are subject to change during the Olympics and Paralympics games. For more information visit www.tfl.gov.uk/buses for more information.",1344668400000]
Use JSONObject like that tutorial shows, you should get a NSDictionary or NSArray at the end which will contain all your values just map those to the label in the end.
If you dont wan to do that, save the response in a char array and navigate through it while checking for [ or " characters when you find one read the chars until the next occurrence and save all the data you read into an array or something but this is messy and involves atleast 3-4 hours of writing your own custom logic for JSON data decryption, you should use JSONObject which is pretty simple
Hi i have this same problem. I have been looking for a json solution and currently i found that the best way to deal with this data is to parse is as csv instead. The solution seems straight up when you try to parse it as CSV instead of JSON

NSXMLDocument parsing into custom objects

Using NSXMLDocument, without using XPath, is there an easy way to parse an XML document and deserialize it into custom objects to create an object tree hierarchy?
For example, if I have the xml shown below, is it possible to put the details into a Restaurant object and a content object within it?
<restaurants>
<content>spanish name</content>
<content>english name</content>
</restaurant>
<spa>
<content>spa spanish name</content>
<content>spa english name</content>
</spa>
I will be using your answer above to extend it for programming in kissxml in iOS. As the kissXML document mentions that the XML parser behaves in the same way as NSXMLDocument, so I've asked the question using NSXMLDocument.
If you know your expected content structure, the easiest is to just use NXMLParser and loop through it looking for the bits you need and keeping track of the previous bit, building an object as you find them.
If you want tree-based approach, consider learning XQuery and XPath, they are not all that bad. Without them, the only thing NSXMLDocument really gives you is Cocoa bindings.
At the end of the day you must transform your data somehow.
With NSXMLDocument you will still do well to validate against an XML DTD if possible, to ensure you have good data.
With NSXMLParser, you are able to handle things without a formal DTD.
You only need worry about how big the data is, an how you want to parse it, then do some trial and error with test data to ensure it's grabbing what you want or need.

Resources