Fork me on GitHub

Index


Home Downloading Installing into Xcode
Creating documents Manipulating documents XPath queries Messaging URLs Messaging web services Error handling
API reference

Building dXml

BSD License

Download latest
static library
v0.1.4

dXml

by Derek Clarkson (d4rkf1br3 [at] gmail.com)

dXml is an iPhone static library providing xml parsing into document models, XPath expressions, xml messaging to/from servers SOAP messaging to/from web service providers and SOAP fault handling.

It was written because I wanted to be able to talk to some SOAP based web services and found no support within the Apple SDK apart from the NSXMLParser class.

Currently it provides the following features:

A quick example

To give you an idea of how simple dXml makes working with SOAP, here is a quick example which does the following:

  1. Setup a connection to a web service.
  2. Post a SOAP message to the service and retrieve the reply.
  3. Check the reply for errors.
  4. Pretty print the response SOAP message to the log.

You can cut and past this into a file and run it using GH-Unit.

 1 #import "GHUnit.h"
 2 #import "DCSoapWebServiceConnection.h"
 3 #import "dXml.h"
 4 #import "DCXmlNode+AsString.h"
 5 
 6 @interface InternetTests : GHTestCase
 7 {}
 8 
 9 @end
10 
11 @implementation InternetTests
12 
13 - (void) testViiumCom {
14 
15    // The request.
16    NSString * request = 
17       @"<Hello xmlns=\"http://viium.com/\">"
18       @"<name xsi:type=\"xsd:string\">Test</name>"
19       @"</Hello>";
20 
21    // Setup the connection.
22    DCSoapWebServiceConnection * connection = [DCSoapWebServiceConnection 
23       createWithUrl:@"http://viium.com/WebService/HelloWorld.asmx" 
24       soapAction:@"http://viium.com/Hello"];
25 
26    // Make the request and get the response.
27    NSError * error = nil;
28    DCWebServiceResponse * response = [connection postXmlStringPayload:request errorVar:&error];
29 
30    // Error check.
31    if (response == nil){
32       NSLog(@"Error %@", error);
33       return;
34    }
35 
36    // Log output.
37    NSLog(@"Results: %@", [[response bodyContent] asPrettyXmlString]);
38 
39 }
40 
41 @end

This is a very simple example. More typically you would be parsing the xml string into a document and then setting values first. Also note that whilst not obvious, dXml is parsing the response from the web service into it’s own document model and storing it inside the response object. Another point of interest is the error handling. Very simple here, but usually you would use methods from a category dXml applies to the NSError class which can tell you if there is a SOAP fault and provide the data from it.

Dependencies

If you just want to use the static library then there are no dependencies.

If you wish to compile the code then you will need the following APIs:

dUsefulStuff

dUsefulStuff is a project that I have created to centralise stuff I want to use across many projects. Some of that are a set of bash scripts which I use to build projects such as this. You will need to either download the project dmg file or check out the project to get the scripts.

appledoc

Appledoc runs and reads the output from doxygen, then reprocesses it to give it a more “Apple like” apperance before installing your api documentation as a docset in xcode.

GH-Unit

GH-Unit is a JUnit style unit testing framework for iPhone applications. The advantages of it over the sen testing framework that comes with xcode is that it runs on the simulator, allows full debugging and is dead simple to use.

OCMock

OCMock is a mocking framework very much like the java EasyMock framework. It’s a very useful tool for “simulating” instances of classes when testing.

Please refer to the Building dXml page for details on building dXml.