Advertisement
Guest User

Untitled

a guest
May 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. //
  2. // LibXSLTViewController.m
  3. // LibXSLT
  4. //
  5. // Created by Elisabel GENEREUX on 10-05-13.
  6. //
  7.  
  8. #import "LibXSLTViewController.h"
  9. #import <libxml/xmlmemory.h>
  10. #import <libxml/debugXML.h>
  11. #import <libxml/HTMLtree.h>
  12. #import <libxml/xmlIO.h>
  13. #import <libxml/xinclude.h>
  14. #import <libxml/catalog.h>
  15. #import <libxslt.framework/Headers/xslt.h>
  16. #import <libxslt.framework/Headers/xsltInternals.h>
  17. #import <libxslt.framework/Headers/transform.h>
  18. #import <libxslt.framework/Headers/xsltutils.h>
  19.  
  20. @implementation LibXSLTViewController
  21.  
  22.  
  23.  
  24. /*
  25. // The designated initializer. Override to perform setup that is required before the view is loaded.
  26. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  27. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  28. // Custom initialization
  29. }
  30. return self;
  31. }
  32. */
  33.  
  34. /*
  35. // Implement loadView to create a view hierarchy programmatically, without using a nib.
  36. - (void)loadView {
  37. }
  38. */
  39.  
  40. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  41. - (void)viewDidLoad {
  42.  
  43. NSString* filePath = [[NSBundle mainBundle] pathForResource: @"xmlDoc" ofType: @"xml"];
  44. NSString* styleSheetPath = [[NSBundle mainBundle] pathForResource: @"xsltDoc" ofType:@"xml"];
  45.  
  46. xmlDocPtr doc, res;
  47.  
  48. // tells the libxml2 parser to substitute entities as it parses your file
  49. xmlSubstituteEntitiesDefault(1);
  50. // This tells libxml to load external entity subsets
  51. xmlLoadExtDtdDefaultValue = 1;
  52.  
  53. xmlChar sty = xsltParseStylesheetFile((const xmlChar *)[styleSheetPath cStringUsingEncoding: NSUTF8StringEncoding]);
  54. doc = xmlParseFile([filePath cStringUsingEncoding: NSUTF8StringEncoding]);
  55. res = xsltApplyStylesheet(sty, doc, NULL);
  56.  
  57. char* xmlResultBuffer = nil;
  58. int length = 0;
  59.  
  60. xsltSaveResultToString(&xmlResultBuffer, &length, res, sty);
  61.  
  62. NSString* result = [NSString stringWithCString: xmlResultBuffer encoding: NSUTF8StringEncoding];
  63.  
  64. NSLog(@"Result: %@", result);
  65.  
  66. free(xmlResultBuffer);
  67.  
  68. xsltFreeStylesheet(sty);
  69. xmlFreeDoc(res);
  70. xmlFreeDoc(doc);
  71.  
  72. xsltCleanupGlobals();
  73. xmlCleanupParser();
  74.  
  75. [super viewDidLoad];
  76. }
  77.  
  78.  
  79. /*
  80. // Override to allow orientations other than the default portrait orientation.
  81. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  82. // Return YES for supported orientations
  83. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  84. }
  85. */
  86.  
  87. - (void)didReceiveMemoryWarning {
  88. // Releases the view if it doesn't have a superview.
  89. [super didReceiveMemoryWarning];
  90.  
  91. // Release any cached data, images, etc that aren't in use.
  92. }
  93.  
  94. - (void)viewDidUnload {
  95. // Release any retained subviews of the main view.
  96. // e.g. self.myOutlet = nil;
  97. }
  98.  
  99.  
  100. - (void)dealloc {
  101. [super dealloc];
  102. }
  103.  
  104. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement