Advertisement
Guest User

Untitled

a guest
Jan 19th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. - (NSXMLDocument *)transform:(NSString *)xml :(NSString *)xslt
  2. {
  3. NSError *xmlDocErr = nil;
  4. NSXMLDocument *transformedXmlDoc = nil;
  5.  
  6. NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
  7. initWithXMLString:xml
  8. options:NSXMLDocumentValidate
  9. error:&xmlDocErr];
  10.  
  11. if (xmlDocErr) {
  12. NSLog(@"Error: %@", [xmlDocErr localizedDescription]);
  13. }
  14. else {
  15. transformedXmlDoc = [xmlDoc objectByApplyingXSLTString:xslt
  16. arguments:nil
  17. error:&xmlDocErr];
  18. if (xmlDocErr) {
  19. NSLog(@"Error: %@", [xmlDocErr localizedDescription]);
  20. }
  21. }
  22.  
  23. return transformedXmlDoc;
  24. }
  25.  
  26. - (NSXMLDocument *)transform:(NSString *)xml :(NSString *)xslt
  27. {
  28. NSError *xmlDocErr = nil;
  29. NSXMLDocument *transformedXmlDoc = nil;
  30.  
  31. NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
  32. initWithXMLString:xml
  33. options:NSXMLDocumentValidate
  34. error:&xmlDocErr];
  35.  
  36. if (xmlDocErr) {
  37. NSLog(@"Error: %@", [xmlDocErr localizedDescription]);
  38. }
  39. else {
  40. // Pipe for stderr
  41. NSPipe *pipe = [NSPipe pipe];
  42. // Duplicate of stderr (will use later)
  43. int cntl = fcntl(STDERR_FILENO,F_DUPFD);
  44. // Redirect stderr through our pipe
  45. dup2([[pipe fileHandleForWriting] fileDescriptor], STDERR_FILENO);
  46.  
  47. transformedXmlDoc = [xmlDoc objectByApplyingXSLTString:xslt
  48. arguments:nil
  49. error:&xmlDocErr];
  50. // Get the data
  51. NSData *dat = [[pipe fileHandleForReading] availableData];
  52. // Redirect stderr through our duplicate, to restore default output behavior
  53. dup2(cntl, STDERR_FILENO);
  54. // Did anything get logged?
  55. if ([dat length]>0) {
  56. NSLog(@"Error: %@", [[NSString alloc] initWithData:dat encoding:NSASCIIStringEncoding]);
  57. }
  58. if (xmlDocErr) {
  59. NSLog(@"Error: %@", [xmlDocErr localizedDescription]);
  60. }
  61. }
  62.  
  63. return transformedXmlDoc;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement