Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -121,10 +121,19 @@ * \param string The string to parse * \return A new autoreleased OFXMLElement with the contents of the string */ + elementWithXMLString: (OFString*)string; +/** + * Parses the specified file and returns an OFXMLElement for it. + * + * \param path The path to the file + * \return A new autoreleased OFXMLElement with the contents of the specified + * file + */ ++ elementWithFile: (OFString*)path; + /** * Initializes an already allocated OFXMLElement with the specified element * name. * * \param name The name for the element @@ -213,10 +222,19 @@ * \param string The string to parse * \return An initialized OFXMLElement with the contents of the string */ - initWithXMLString: (OFString*)string; +/** + * Parses the specified file and initializes an already allocated OFXMLElement + * with it. + * + * \param path The path to the file + * \return An initialized OFXMLElement with the contents of the specified file + */ +- initWithFile: (OFString*)path; + /** * \return The name of the element */ - (OFString*)name; Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -123,10 +123,15 @@ + elementWithXMLString: (OFString*)string { return [[[self alloc] initWithXMLString: string] autorelease]; } + ++ elementWithFile: (OFString*)path +{ + return [[[self alloc] initWithFile: path] autorelease]; +} - init { Class c = isa; [self release]; @@ -266,10 +271,49 @@ [parser setDelegate: builder]; [builder setDelegate: delegate]; [parser parseString: string]; + + if (![parser finishedParsing]) + @throw [OFMalformedXMLException newWithClass: c + parser: parser]; + + self = [delegate->element retain]; + + @try { + [pool release]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithFile: (OFString*)path +{ + OFAutoreleasePool *pool; + OFXMLParser *parser; + OFXMLElementBuilder *builder; + OFXMLElement_OFXMLElementBuilderDelegate *delegate; + Class c; + + c = isa; + [self release]; + + pool = [[OFAutoreleasePool alloc] init]; + + parser = [OFXMLParser parser]; + builder = [OFXMLElementBuilder elementBuilder]; + delegate = [[[OFXMLElement_OFXMLElementBuilderDelegate alloc] init] + autorelease]; + + [parser setDelegate: builder]; + [builder setDelegate: delegate]; + + [parser parseFile: path]; if (![parser finishedParsing]) @throw [OFMalformedXMLException newWithClass: c parser: parser];