XML files are used widely around in the programming environment, so with this useful function you can open a file and get its XML representation.
/** Opens a XML file and returns a XML object.
Based on GDataXML ( http://code.google.com/p/gdata-objectivec-client ).
@param filePath String representing full path of the file to open.
@return Returns a GDataXMLDocument initialized with XML data taken from XML file, or nil in case of error.
*/
+ (GDataXMLDocument *)openXmlAtPath:(NSString *)filePath {
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSError *err;
GDataXMLDocument *obj = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&err];
if (obj == nil) {
return nil;
}
return obj;
}
Download the ready-for-use source file (.m) of Get XML data from file
No comments:
Post a Comment