Last active
December 27, 2015 16:59
-
-
Save krhoyt/7359128 to your computer and use it in GitHub Desktop.
Create an XML document and write it to disk.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- ( void ) createAndWriteXMLDocument : ( NSString * ) fileName | |
{ | |
NSArray * directories; | |
NSData * output; | |
NSFileManager * manager; | |
NSMutableString * path; | |
NSXMLDocument * doc; | |
NSXMLElement * root; | |
NSXMLNode * first; | |
NSXMLNode * last; | |
root = ( NSXMLElement * )[NSXMLNode elementWithName : @"person"]; | |
doc = [[NSXMLDocument alloc] initWithRootElement : root]; | |
[doc setVersion:@"1.0"]; | |
[doc setCharacterEncoding:@"UTF-8"]; | |
first = [[NSXMLNode alloc] initWithKind : NSXMLElementKind]; | |
[first setName : @"first"]; | |
[first setObjectValue : @"Kevin"]; | |
[root addChild : first]; | |
last = [[NSXMLNode alloc] initWithKind : NSXMLElementKind]; | |
[last setName : @"last"]; | |
[last setObjectValue : @"Hoyt"]; | |
[root addChild : last]; | |
manager = [NSFileManager defaultManager]; | |
directories = NSSearchPathForDirectoriesInDomains( NSDesktopDirectory, NSUserDomainMask, YES ); | |
path = [[NSMutableString alloc] initWithString : [directories objectAtIndex : 0]]; | |
[path appendString: @"/"]; | |
[path appendString: fileName]; | |
output = [doc XMLDataWithOptions : NSXMLNodePrettyPrint]; | |
[output writeToFile: path atomically:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment