Re: Passing arrays via WSMethodInvocationInvoke() [WebServicesCore]
Re: Passing arrays via WSMethodInvocationInvoke() [WebServicesCore]
- Subject: Re: Passing arrays via WSMethodInvocationInvoke() [WebServicesCore]
- From: Dan Korn <email@hidden>
- Date: Mon, 26 Oct 2009 15:49:51 -0500
Quoting myself:
1. Is there any Cocoa object, or combination of objects, that I can
use to generate the required XML without having to call
WSMethodInvocationAddSerializationOverride()?
I still haven't found an answer to this.
2. Is there something built-in I can call in my serialization override
function to properly encode the data, escaping XML control characters
with entities and such, in the same way that the default serialization
works?
After a lot of experimenting with NSArchiver and NSCoder to no avail,
I finally stumbled upon the CFXMLCreateStringByEscapingEntities()
function, which seems to do what I want, although I still think I must
be missing some "NS" way of doing this. So, here's my updated
serialization function:
static CFStringRef _arrayToXML(WSMethodInvocationRef invocation,
CFTypeRef obj, void *info)
{
if (obj != nil && (CFGetTypeID(obj) == CFArrayGetTypeID()))
{
NSArray* array = (NSArray*)obj;
NSMutableString* result = [[NSMutableString alloc]
initWithFormat:@"<%s>", "%@"];
for (int i = 0; i < [array count]; i++)
{
NSString* rawString = [array objectAtIndex:i];
CFStringRef markup = CFXMLCreateStringByEscapingEntities
(kCFAllocatorDefault, (CFStringRef)rawString, NULL);
[result appendFormat:@"<string>%@</string>", markup];
}
[result appendFormat:@"</%s>", "%@"];
return (CFStringRef)result;
}
return NULL;
}
Again, apologies if there's a more appropriate forum for this; please
redirect me.
Thanks,
Dan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden