From the API reference:
...
How do I know or control if the return type is NSXMLDocument or NSData? I used this code from the NSXML_Concepts document, only changing the xsltPath to point to my XSLT code, but I was returned an NSData object. I don't have a problem with that, but I'm curious why.
Here is my code. It works fine, and newXMLDoc is NSData. That's fine because I want to write it to a file, but I expected another step to get an NSData from the NSXMLDocument first.
Code:
objectByApplyingXSLTAtURL:arguments:error:
Applies the XSLT pattern rules and templates located at a specified URL to the receiver and returns a document object containing transformed XML markup or an NSData object containing plain text, RTF text, and so on.
- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)arguments error:(NSError **)error
Code:
Return Value
Depending on intended output, the returns an NSXMLDocument object or an NSData data containing transformed XML or HTML markup. If the message is supposed to create plain text or RTF, then an NSData object is returned, otherwise an XML document object. The method returns nil if XSLT processing did not succeed.
How do I know or control if the return type is NSXMLDocument or NSData? I used this code from the NSXML_Concepts document, only changing the xsltPath to point to my XSLT code, but I was returned an NSData object. I don't have a problem with that, but I'm curious why.
Code:
// find XSLT code
NSString *xsltPath = [[NSBundle mainBundle]
pathForResource:@"addresses_transform" ofType:@"xml"];
if (!xsltPath)
return;
// transform through XSLT
NSXMLDocument *printDoc = (NSXMLDocument *)[xmlDoc
objectByApplyingXSLTAtURL:[NSURL fileURLWithPath:xsltPath]
arguments:nil error:&err];
Here is my code. It works fine, and newXMLDoc is NSData. That's fine because I want to write it to a file, but I expected another step to get an NSData from the NSXMLDocument first.
Code:
// Create NSURL with arg 3
NSURL *xsltUrl = [NSURL fileURLWithPath:[args objectAtIndex:3]];
if (!xsltUrl)
{
NSLog(@"Can't create an URL from XSLT file %@.", [args objectAtIndex:3]);
return 1;
}
// Apply xslt to NSXML Document
newXMLDoc = [xmlDoc objectByApplyingXSLTAtURL:xsltUrl arguments:nil error:&err];
[newXMLDoc retain];
if (newXMLDoc == nil) {
if (err) {
NSLog(@"UNABLE TO OPEN XSLT FILE: %@",[args objectAtIndex:3]);
}
return 1;
}