Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // LibXSLTViewController.m
- // LibXSLT
- //
- // Created by Elisabel GENEREUX on 10-05-13.
- //
- #import "LibXSLTViewController.h"
- #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.framework/Headers/xslt.h>
- #import <libxslt.framework/Headers/xsltInternals.h>
- #import <libxslt.framework/Headers/transform.h>
- #import <libxslt.framework/Headers/xsltutils.h>
- @implementation LibXSLTViewController
- /*
- // The designated initializer. Override to perform setup that is required before the view is loaded.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- NSString* filePath = [[NSBundle mainBundle] pathForResource: @"xmlDoc" ofType: @"xml"];
- NSString* styleSheetPath = [[NSBundle mainBundle] pathForResource: @"xsltDoc" 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;
- xmlChar 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();
- [super viewDidLoad];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)dealloc {
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement