NSFileWrapper with XML document

  • Hello everyone,

    I can't figure out why this is throwing an error:

    - (NSFileWrapper *)fileWrapperRepresentationOfType:(NSString *)aType {
    NSMutableDictionary *contents = [NSMutableDictionary dictionary];

    NSXMLElement *rootElement = (NSXMLElement *)[NSXMLNode
    elementWithName:@"document"];
    NSXMLDocument *xmlDocument = [[NSXMLDocument alloc]
    initWithRootElement:rootElement];

    [contents setObject:xmlDocument forKey:[[NSString alloc]
    initWithString:@"properties.xml"]];
    NSFileWrapper *documentBundle = [[NSFileWrapper alloc]
    initDirectoryWithFileWrappers:contents];

    return [documentBundle autorelease];
    }

    The Error:

    [Session started at 2007-10-27 21:47:30 -0500.]
    2007-10-27 21:47:42.606 ApplicationName[2087] *** -[NSXMLDocument
    preferredFilename]: selector not recognized [self = 0x3c9130]
    2007-10-27 21:47:42.612 ApplicationName[2087] *** -[NSXMLDocument
    preferredFilename]: selector not recognized [self = 0x3c9130]

    besides releasing the rootElement and xmlDocument am I doing anything
    wrong?
  • On Oct 27, 2007, at 9:49 PM, Rick Langschultz wrote:

    > Hello everyone,
    >
    > I can't figure out why this is throwing an error:
    >
    > - (NSFileWrapper *)fileWrapperRepresentationOfType:(NSString *)aType {
    > NSMutableDictionary *contents = [NSMutableDictionary dictionary];
    >
    > NSXMLElement *rootElement = (NSXMLElement *)[NSXMLNode
    > elementWithName:@"document"];
    > NSXMLDocument *xmlDocument = [[NSXMLDocument alloc]
    > initWithRootElement:rootElement];
    >
    > [contents setObject:xmlDocument forKey:[[NSString alloc]
    > initWithString:@"properties.xml"]];
    > NSFileWrapper *documentBundle = [[NSFileWrapper alloc]
    > initDirectoryWithFileWrappers:contents];
    >
    > return [documentBundle autorelease];
    > }
    >
    > The Error:
    >
    > [Session started at 2007-10-27 21:47:30 -0500.]
    > 2007-10-27 21:47:42.606 ApplicationName[2087] *** -[NSXMLDocument
    > preferredFilename]: selector not recognized [self = 0x3c9130]
    > 2007-10-27 21:47:42.612 ApplicationName[2087] *** -[NSXMLDocument
    > preferredFilename]: selector not recognized [self = 0x3c9130]
    >
    > besides releasing the rootElement and xmlDocument am I doing
    > anything wrong?

    Yes. -[NSFileWrapper initDirectoryWithFileWrappers:] expects a
    dictionary that contains NSFileWrapper's, not NSXMLDocument's.
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today