Archive of UserLand's first discussion group, started October 5, 1998.

Re: XML-RPC for WebObjects/Objective-C?

Author:Jonathan Hendry
Posted:4/1/1999; 8:56:48 AM
Topic:XML-RPC for WebObjects/Objective-C?
Msg #:4732 (In response to 4722)
Prev/Next:4731 / 4733

N.B.: Please pardon the formatting horrors. Thanks.

"PropertyLists might do it, although I would think you'd want to parse the xml into an actual object graph"

To do this, first create an NSString instance containing the converted XML. Then call the string's -propertyList method. You'll get back objects, probably an NSDictionary at the top level.

("PropertyList" is kind of an overloaded term. In one sense it applies to the ASCII format in which PropertyLists are stored. In another sense it applies to the object graph created from the ASCII.)

The catch would be that the objects would all be FoundationKit primitives - NSArray, NSDictionary, and NSString. However, once you've got that it wouldn't be difficult to convert them to less generic objects.

The actual conversion of an XML message to propertyList format may be pretty straightforward. Here's an example propertyList:

{

SuiteName = TimeApps;

HideOnStartup = NO;

ConnectionData = (

{

databaseName = Time;

hostName = foo;

password = "bar";

userName = jabba;

}

);

}

A dictionary is marked by the enclosing {}, and contains

semicolon separated key-value pairs. An Array is

marked by enclosing parenthesis, and the elements

are separated by commas; there's a one-element array

in this dictionary. If an element isn't an array or

a dictionary, it's either a string (which can be converted

to a number) or an NSData, which stores binary data in an

ASCII-friendly format.

(These just apply to ASCII format. When dealing with objects,

you can use any class.)

Using an example from http://www.scripting.com/Frontier5/xml/code/rpc.html, a

conversion might look like this:

XML:

POST /RPC2 HTTP/1.0

User-Agent: Frontier/5.1.2 (WinNT)

Host: betty.userland.com

Content-Type: text/xml

Content-length: 181

examples.getStateName

41

PropertyList:

{

Request = "POST /RPC2 HTTP/1.0";

User-Agent = "Frontier/5.1.2 (WinNT)";

Host = betty.userland.com;

Content-Type = "text/xml";

Content-length = 181;

"XML Version" = "1.0";

methodCall = {

methodName = examples.getStateName;

params = (

{

value = 41;

format = int;

}

)

};

}

The Property List is a Dictionary. The value of the

methodCall key is another dictionary. That dictionary

has a params key, whose value is an array of dictionaries.




This page was archived on 6/13/2001; 4:49:10 PM.

© Copyright 1998-2001 UserLand Software, Inc.