Parsing and Writing XML in MAC 10.3.9 Cocoa? - objective-c

What is the Best way i can do Parsing or Writing into XML using cocoa for mac10.3.9.?
Im mentioning the version of OS specifically because, i read in the documentation like, Mac 10.3.9 sdk does not support NSXML class.?
I Found an OpenSource libaray (libxml), is it the only library i can use????
Please give me some suggestion regarding the above....
Kindly reply Soon...
Thank you
Pradeep.

According to my copy of the documentation, the NSXMLParser class is available on Mac OS X 10.3 and later.
If for some reason you cannot use that, you can also use the Core Foundation XML Parser functions (search for CFXMLParser). This is a C-based API also developed by Apple. It will be deprecated in future versions of Mac OS X (after Snow Leopard), but since you're working on 10.3 that won't be a concern for you.
Many who cannot use those two also use libxml. Objective-C is able to use any C-based libraries with no penalty. I'm fairly certain Mac OS X ships with a copy of libxml you can link to (no need to download, build, or ship the library yourself; though if you want to, you certainly can).
What's best is going to depend on what features you need. Namespaces, for example, aren't fully supported by NSXMLParser in 10.3, but they are supported in 10.4.

Thanks for the replies....
I used libxml for xml parsing, it was working fine.
But still it has some problems like, even if the xml file is half consistent(i mean if the xml is corrupt, it loads the xml file).
libxml with xpath made things quite easy for xml parsing.

Related

Generate Objective-C code from any other language

Are there frameworks/generators for producing iOS code from any other language?
A dynamic language like JavaScript, ruby or Python are preferred. Googling for iOS code generators was largely fruitless.
The problem with systems like PhoneGap is that their output is a full-fledged application. What I need to produce is a library (.a & .h file eventually) that other Objective-C developers can reuse in their projects.
RubyMotion may or may not do what you want. I haven't seen much about the practicalities of it yet, but I'm thinking since it's statically compiled chances are good that it can produce libraries that can be simply linked into Objective-C projects. One might need another tool to produce the header files.
Of course, this is all speculation.
I think the best solution for what you're looking for is Titanium. It has its own sdk (in JavaScript), a complete IDE and allows you to have one codebase for all major platforms (iOS, Android included). What it's really awesome is the fact that it actually generates native code (a valid XCode project or a Java one for Android). It's also free and open source. Definetely worth a look.
I've never seen code generators, but there are a variety of "spoofs" as it were.
http://xamarin.com/monotouch - iOS on C#
http://phonegap.com/ - iOS on HTML, CSS , Javascript
http://ipodtoucher55.blogspot.com/2010/06/how-to-create-iphone-apps-in-flash-cs5.html - one of several tutorials for flash on iOS
I've seen links to python libraries and I think java too.
When it comes down to it though, they're all work arounds, not direct development.

JSON parser for Cocoa

I'm starting with iOs. I'd like to know if there is a built-in JSON parser and , if not, what is the best alternative for mapping JSON string into Cocoa objects.
Thanks
If you are targeting iOS 5 only, then there is the built-in NSJSONSerialization class that will do the job nicely. If you need it to work in older versions of iOS, then something like SBJSON works well for me
There is a built in JSON parser (NSJSONSerialization) in iOS 5 and above.
If you want to target earlier versions of iOS, there are many third party ones such as TouchJSON.
Have you looked at JSONKit
JSONKit
JSONKit is dual licensed under either the terms of the BSD License, or alternatively under the terms of the Apache License, Version 2.0.
Copyright © 2011, John Engelhart.
A Very High Performance Objective-C JSON Library
UPDATE: (2011/12/18) The benchmarks below were performed before Apples NSJSONSerialization was available (as of Mac OS X 10.7 and iOS 5). The obvious question is: Which is faster, NSJSONSerialization or JSONKit? According to this site, JSONKit is faster than NSJSONSerialization. Some quick "back of the envelope" calculations using the numbers reported, JSONKit appears to be approximately 25% to 40% faster than NSJSONSerialization, which is pretty significant.
I use SBJson , it is not a built-in JSON parser, but I recommand it, you can try it.

Developing Linux-compatible Command Line Utility under Mac OS X

which is the best way to develop a linux-compatible Command Line Utility under Mac OS X Lion? It should parse a really big XML file (up to 300 GB) - probably with libxml - and convert it to somewhat JSON.
With XCode 4 there is the possiblity to develop Command Line Utilities (former Foundation Tools I think). Are these compatible to run on Linux Servers? It would be nice, cause I'm used to Objective-C a little bit.
Another approach would be native C. But I'm really no expert in programming C. Alternatives are maybe Perl or Ruby. PHP as CLI script isn't as fast as needed I think.
Any suggestions which is the easiest and at the same time fastest in context of parsing the XML data way?
Thanks in advance
Marco
With speed being a concern with files of that size, I'd be leaning toward C using libxml2 (available on both platforms) and use the progressive (event driven) interface. Other then that, if you stick to posix I/O, you should be fine.
Mac OS also includes a Python implementation. Python's readily available on Linux and has good libraries for both JSON and XML.

Creating custom file extensions on Mac

just curious if anyone knows a good tutorial or some info on how to create a custom file type for an application. By default, XCode uses binary for saves (and it's fully functional) but obviously it's better to have a custom file type for an application, rather than a binary file. Is this easier said than done?
After some false starts in earlier releases, Mac OS X 10.3 introduced the concept of Uniform Type Identifiers (UTI) to describe how files are associated with applications. UTIs try to incorporate all the previous mechanisms, including file extensions, legacy Mac OS file types, MIME types, etc. Applications can declare UTI information in the app bundle Info.plist. There is an overview in the Apple Developer documentation here. By the way, not everyone is convinced that UTIs are the best solution.

Updating sqlite3 API

I want to update/upgrade the standard Leopard install of Sqlite3 to >3.5 to use the new sqlite_xxx_v2 methods from a Cocoa project.
I can't seem to find any information on how to do this. Does anyone have any tips or a site that outlines the update procedure.
Also is 3.5+ supported on the iPhone. I understand it's embedded so shouldn't be an issue...
What you want to do is grab the amalgamation sources from http://sqlite.org/download.html . Then just compile that into / add it to your project. You don't want to replace the system sqlite- that'll have unintended consequences in other applications. Plus, I'm pretty sure the system sqlite isn't a stock sqlite... Apple has probably made their own modifications to it that core data relies on.
You can read up on the amalgamation stuff here: http://sqlite.org/amalgamation.html , but in short: '''The amalgamation is a single C code file, named "sqlite3.c", that contains all C code for the core SQLite library and the FTS3 and RTREE extensions'''
I'd also suggest not using the sqlite calls directly, they weren't designed to be used that way (says the author of sqlite). Instead, there are a number of cocoa wrappers out there, including fmdb: http://code.google.com/p/flycode/source/browse/trunk/fmdb/ (which I wrote) :)
-gus
You don't really want to upgrade the system version of SQLite on Mac OS X. The reason is that all Mac OS X software is qualified against the versions of the packages that it includes, as built by Apple's build process. Installing a different version of a package, or even building the same version yourself but doing so slightly differently than Apple does, may result in a system that behaves unexpectedly.
Finally, if you embed a newer version of SQLite — or any Open Source library or framework included with Mac OS X — into your own application, you should be sure to integrate the Darwin changes for it from Apple's public source site. That way you can be sure you'll get as close to the same behavior as possible from the library you've built yourself as the version Apple ships, which is especially important when it comes to functionality like file locking in databases.
I don't believe i've updated my version, but it's currently at 3.4.2, and i'm able to use the new methods with the current version.
And i'm running 10.5.5 with the latest (public) iPhone SDK.
It would likely be easier to just drop the library into your project and link it in from there.