Recently I began writing an application for my toddler that uses compositions created with quartz composer. I am very impressed with Quartz composer, this is an application that I was unsure of it value in Tiger. QC makes it extremely easy to write and test 2d graphics, especially for kids educational software. QC still has a few short comings but it is progressing along nicely. One of the things I had to work around was QC’s inability to play a sound file. I recently completed writing a audio plugin renderer so that I can play a sound with my composition. One fascinating thing about Qc is that it is possible to write entire games in QC. I have run across asteroids and pong composed entirely in a QC composition.
This writing is along the lines of Soap services. This is another question I see a lot floating around the net. When is it best to use NSXML event parser or Apple’s newer NSXML Tree Based XML Parser? The answer depends on the number of times you will need to get information from the xml document. In other words, will the software require multiple queries of the file to get information or is all of the information in the file going to be presented to the user at one time. The answer here is critical because the NSXML Tree parser can be very memory intensive as the entire XML is read into memory to form the tree to query. The NSML Event parser does not load the file into memory it simply reads the file line by line and sends event notifications to a delegate so that something can be done with the information. I learned this back when I created my TV listings app. The Tree based parser was really slooooow. Querying the XML document by Xpath or Xquery took a long time. One thing I realized is that my app did not need to make multiple queries to the document. It was much easier and much more memory efficient to use the Event parser to gather data and place into containers for later retrieval by the software. What kind of difference did this make. Well it went from 2 to 3 minutes to construct the data and present it to the user with NSXML Tree to 10 to 15 seconds with the event parser. If anyone needs any help with this area please feel free to email me.
If you are wanting some info on Web services and xml in cocoa have a look at Todd Ditchendorf’s blog. He has been very very generous in open sourcing some terrific tools for just such a need.
Here is an old topic that I get a lot of emails about it. About a year or so ago I wrote a cocoa app to get tv listings from SchedulesDirect (formally zap2it datadirect). While writing this application I learned more about cocoa especially WebServices than I had expected. For one thing WebServicesCore is very poorly documented and a bear to understand -it is almost as if someone gave up on the project and moved on to something else. WebServicesCore is not a pure cocoa solution it is a bit low level, core foundation (c based) implementation. It uses CFNetwoks for authentication. However, the service is fully functional and pretty robust once you get the hang of it. When I say robust, I mean for my purpose. My use of WebServiceCore was to access a soap service, send a soap envelope with a request, and download to a file. The completed soap request simply put the file on the local machine so that my program could parse it for the tv listings. The one positive thing about WebServicesCore is that it comes with a small program called WSMakeStubs which will generate code stubs to include in your cocoa project. Simply point it to a WSDL file and it will create files in either core foundation or applescript. The following is a general rundown of what WebCoreServices does:
- Creates a soap request
- Invokes soap request
- Get HTTP authorization request
- Invoke Soap request
Here is a little tidbit of information about WebServicesCore.
- Under Xcode 2.x the header files are located under the foundation framework. However, in Xcode 3.0 it is now under the CoreServices frameworks.
- For more information on WebServicesCore topic visit Todd Ditchendorf,s Blog. I have never meet this person but this is an area he seems to be an expert.
A different approach I learned a little later on that for a simple download request from a soap server I could use a pure cocoa implementation URL Loading System. By using NSURL I could simply create a soap envelope with [NSString stringWithFormat] and send it along to get the file. However a word of caution, this is not good for lets say a flickr web service or a similar sites. It is just to slow. Works still the same for download request. I find this method to be quite simple and fast for my purposes. A Brief rundown of Using NSURL
- Get HTTP authentication challenge
- send soap request
For more information on using Cocoa’s URL loading system see the URL Loading System Programming Guide.
There are other software options that provide code stubs for WebServies