til*_*lda 14 iphone xslt cocoa-touch
我打算在我的iPhone应用程序中使用XML/XSLT.
iPhone目前支持哪个版本的XSLT?我可以使用XSLT 2.0还是只使用1.0?
rpi*_*ing 15
使用libxslt在iPhone OS其实很简单:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include/libxml2).最后,您可以使用类似于上面示例的代码将转换结果转换为NSString(例如,以a显示UIWebView):
#import <libxml/xmlmemory.h>
#import <libxml/debugXML.h>
#import <libxml/HTMLtree.h>
#import <libxml/xmlIO.h>
#import <libxml/xinclude.h>
#import <libxml/catalog.h>
#import <libxslt/xslt.h>
#import <libxslt/xsltInternals.h>
#import <libxslt/transform.h>
#import <libxslt/xsltutils.h>
...
NSString* filePath = [[NSBundle mainBundle] pathForResource: @"article" ofType: @"xml"];
NSString* styleSheetPath = [[NSBundle mainBundle] pathForResource: @"article_transform" ofType:@"xml"];
xmlDocPtr doc, res;
// tells the libxml2 parser to substitute entities as it parses your file
xmlSubstituteEntitiesDefault(1);
// This tells libxml to load external entity subsets
xmlLoadExtDtdDefaultValue = 1;
sty = xsltParseStylesheetFile((const xmlChar *)[styleSheetPath cStringUsingEncoding: NSUTF8StringEncoding]);
doc = xmlParseFile([filePath cStringUsingEncoding: NSUTF8StringEncoding]);
res = xsltApplyStylesheet(sty, doc, NULL);
char* xmlResultBuffer = nil;
int length = 0;
xsltSaveResultToString(&xmlResultBuffer, &length, res, sty);
NSString* result = [NSString stringWithCString: xmlResultBuffer encoding: NSUTF8StringEncoding];
NSLog(@"Result: %@", result);
free(xmlResultBuffer);
xsltFreeStylesheet(sty);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
Run Code Online (Sandbox Code Playgroud)
正如Lou Franco所指出的那样,iPhone上不允许使用dylib.
它在模拟器和手机中都可以正常开发,但是一旦你将它提交给Apple批准它就会被拒绝.我的应用程序在大约20分钟内被拒绝,可能是他们的自动静态分析工具.
相反,下载源代码,将其添加到项目中,链接LibXML2.2.dylib(不要问我为什么允许这个dylib但是XSLT不是!)并构建项目.这几乎是你所要做的.感谢Lou,因为正是他指出了我正确的方向.