Pages

Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

August 19, 2013

Get XML data from file

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