How to write to an XML file from iOS? - ios

I am developing an app for iPad, and I need to modify several attributes in a XML file at runtime.
I found the class NSXMLDocument. But I haven't been able to import it to my project.
Is this class not available for iPhone/iPad development?
Is there some other approach I can consider?
I read about libxml library. Is it my answer or there is a better approach?

NSXMLDocument is MacOS X Cocoa only. You have available on iPhone NSXMLParser, and several external libraries built on libxml2 - TouchXML, KissXML and a couple of others.
Note that KissXML supports writing XML.
Other XML libraries that have been suggested include the XML support from Google Data and VTD-XML.

You are looking for a DOM XML parser, which is best for modification of XML documents. See for example this tutorial - without mapping to and from Model Objects - use the XPath.

Related

How to generate Swift/Objective-C classes from a DTD file?

I have a given huge DTD file and I want to generate my classes for an iOS project automatically. Preferably Swift or Objective-C classes. Is there any tool that could do the trick? I did some research and only found generators for Java and C#.

How to generate an XML document in iOS using objective-c

I want to generate an XML document in iOS. My primary goal is to generate it using inbuilt classes/libraries. I researched a lot and I found that NSXMLElement, NSXMLDocument etc are used to generate XML in OS X but not in iOS (correct me if I'm wrong about this). I found some of the third party libraries like GDataXML, APXML etc which generates the XMLDocument as per my needs. But, I'm trying hard to achieve the same using inbuilt classes (if any). BTW, I do not want the strings to be appended manually to create XML.
I'm not expecting a complete code which does the generation. Any help/suggestion on any inbuilt classes would be appreciated.
Thanks in advance.
You're right -- you need to look for a 3rd party solution for XML writing in iOS. For parsing, there is NSXMLParser.

programmatically generate ppt in iOS

For generating PDF files we can use Core Graphics. Similarly is there any framework / class that can be used for generating .ppt (power point presentation) files via code ? Or is there any third party framework for this purpose.
There's no in-built Apple API, and I've never heard of a third-party framework for this.
Seems there are still no open source solutions for this for iOS platform. Aspose seems to have something and another commercial that pretty recently emerged - libpptx.com, at least it provides some generic functionality to craft pptx

Phone directory in iOS

I am creating a IOS phone directory app. I am trying to download a XML file from a url. This XML file will then be used to populate the directory app with phone numbers, names and identifications of all the people in the directory. I'm new to IOS development and I'm looking for any information or assistance on where to get started on how to parse the XML file.
What is included with Cocoa is NSXMLParser, and you can download the source code imageMap. There are also other third party libraries such as TouchXML and TBXML. Although in my experience TouchXML has some memory leaks issues that can create a lot of problems. And the one that has given me the fastest results is TBXML by far.
You can find a detailed article on all the available third-party parsers available here: Best xml parser for your app
TBXML is the way to go IMO. I have a complete code sample if you need it. If you post the structure of that XML file, I can modify the sample to fit your needs.
If you are creating the webserver manually, then I would look into using JSON instead of XML. It's a bit easier to work with. If you need to use XML, the NSXML parser class works pretty well. Here is a good tutorial: http://www.xcode-tutorials.com/parsing-xml-files/
Or you could check out chapter 21 I believe of the big nerd ranch iPhone programming book for a more detailed explination.
Good Luck!

Can I use UIDocument in a Mac OSX app?

I would like to share a common document format between iOS and OSX. Note that this is not an MDI application; there will ever be one document to save/load. NSDocument style user driven management (e.g.. Save, Save As, Open etc.) is not required.
The biggest challenge is there seems to be no common document encoding format naturally compatible with OSX and IOS (yet). According to Document-Based Application Programming Guide for iOS, it looks like encoding/decoding conversion is required between NSDocument and UIDocument derived classes. I wish there is a universal serialization mechanism compatible with all devices across Apple ecosystem. Any thoughts, ideas, tips are appreciated in this regard.
Can I use a UIDocument derived class in my mac osx application and the document becomes compatible with IOS?
No, you can't use or subclass UIDocument in a Cocoa application because UIDocument doesn't exist in Cocoa.
In both NSDocument and UIDocument, you determine the format that you will use. So, just implement them both to use the same format for the output and the input.
It wouldn't be too hard to use the preprocessor to set up a file-pair that implements a subclass of NSDocument when building for the Mac and UIDocument when building for iOS. This would prevent you from having mismatched serialization and deserialization implementations, since you'd have only one copy of each and be using it on both platforms.
Peter's answer above is correct, but I have a suggestion that does not involve the C pre-processor (not available in Swift) that is a bit more Cocoa-like.
Watch WWDC 2014 session 233 to set up your iOS and Mac apps in a single Project as separate targets, then use Categories on your document class to implement the common functionality:
CommonFunctions.h
#interface AppDocument (CommonFunctions)
- (void)function;
#end
-
CommonFunctions.m
#implementation AppDocument (CommonFunctions)
- (void) function {
/// stuff here
}
#end
Your AppDocument class would have 2 different classes inheriting from UI/NSDocument as necessary for each platform/target, and each target would pull in the categories from a common place.

Resources