• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with CFXMLTreeCreateFromData with an NSMutableURLRequest response.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with CFXMLTreeCreateFromData with an NSMutableURLRequest response.


  • Subject: Re: Help with CFXMLTreeCreateFromData with an NSMutableURLRequest response.
  • From: Jerry Krinock <email@hidden>
  • Date: Sat, 19 Mar 2005 11:34:59 -0800

on 05/03/19 06:53, Scott Andrew at email@hidden wrote:

> The server that I am interacting with is using literals for "&" and not
> &amp;. Is there a way to get NSString or NSData to properly encode this?
> Since its a one time shot read I could write my own parser the nodes are
> always the same format..

I was having a problem with &amp etc. last year, and someone on this list
pointed out to me that there are Cocoa functions which can parse xml
property lists.  I'm not sure if that will help you, but you might want to
have a look at the demo code which follows.  Although I decided to keep
using Core Foundation and solved my &amp problem by brute force, I believe
that, if I were to doing a rewrite from scratch, something baseed on this
demo would be the way to go.  It "just works".

Jerry

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"\n\n*** Bookmarks Before sorting ***") ;
    // 1.  Create NSDictionary and NSEnumerator of bookmarks
    // 1.1  Read bookmarks from file to an NSData
    // Note that the bookmarks file must be placed in the folder with the
executable.
    NSString *path = @"BookmarksTestData.plist" ;
    NSData *data = [NSData dataWithContentsOfFile:path];

    // These lines are for debugging only
    NSFileHandle *standardOut = [NSFileHandle fileHandleWithStandardOutput];
    [standardOut writeData:data];

    // 1.2  Convert the NSData to an NSDictionary
    NSDictionary *bookmarksTopLevel = [NSPropertyListSerialization
propertyListFromData:data

mutabilityOption:NSPropertyListMutableContainers

format:NULL

errorDescription:NULL];

    // 1.3  Create a single NSEnumerator from the NSDictionary
    NSEnumerator *bookmarkLocationEnumerator = [[bookmarksTopLevel
objectForKey:@"Children"] objectEnumerator];
    // 1.4  Create an NSDictionary for storing the current location as we
traverse the bookmarks
    NSDictionary *bookmarkLocation;

    // 1.5  For each object in the enumerator,
    while (bookmarkLocation = [bookmarkLocationEnumerator nextObject])
    {
        NSLog(@"\n\n\n*** Next object ***:");
        NSLog([bookmarkLocation description]) ;
        NSLog(@"\n\n\n");
        // Find the object "Children" which is an array, and declare a
pointer to it
        NSMutableArray *bookmarks = [bookmarkLocation
objectForKey:@"Children"];
        if (bookmarks != nil)
        {
            NSLog(@"\n\n\n*** This object has the following children:
***:");
            NSLog([bookmarks description]) ;
            NSLog(@"\n\n\n");
        }
        else
            NSLog(@"*** This object has no children ***") ;
        // Sort these children
        // Sort these children, if any
        /* If no "Children" object was found, bookmarks will be nil, and the
         following will not run, since in Objective-C if you send a
         message which normally returns ab object to nil, nothing happens */
        [bookmarks
sortUsingSelector:@selector(uriDictionaryTitlesAlphabeticallyCompare:)];

    }

    // Convert the sorted dictionary back to an NSData
    NSData *newData = [NSPropertyListSerialization
dataFromPropertyList:bookmarksTopLevel

format:NSPropertyListXMLFormat_v1_0

errorDescription:NULL];

    NSLog(@"\n\n*** Bookmarks After sorting ***") ;
    [standardOut writeData:newData];

    [pool release];
    return 0;
}

@implementation NSDictionary (Helper)

- (NSComparisonResult)uriDictionaryTitlesAlphabeticallyCompare:(NSDictionary
*)otherDictionary
{
    NSLog(@"Sorting...") ;
    return [(NSString *)[self valueForKeyPath:@"URIDictionary.title"]
compare:[otherDictionary valueForKeyPath:@"URIDictionary.title"]];
}

@end


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Help with CFXMLTreeCreateFromData with an NSMutableURLRequest response. (From: Scott Andrew <email@hidden>)

  • Prev by Date: Re: newbie memory issues continued
  • Next by Date: Tools for creating icons
  • Previous by thread: Re: Help with CFXMLTreeCreateFromData with an NSMutableURLRequest response.
  • Next by thread: Re: Help with CFXMLTreeCreateFromData with an NSMutableURLRequest response.
  • Index(es):
    • Date
    • Thread