Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-18-2010, 04:51 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 3
tmoney11 is on a distinguished road
Default Parse XML before loading into NSMutableDictionary

I'm not sure exactly if this is possible but I wanted to see if anybody can point me in the right direction.

So I'm using MGTwitterEngine and I want the XML parser to only add status messages that have a particular phrase or trend (#music). This way only statuses that contain that phrase are actually added to the Dictionary.

Here is the MGTwitterStatusesParser code:

Code:
- (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict
{
  //  NSLog(@"Started element: %@ (%@)", elementName, attributeDict);
    [self setLastOpenedElement:elementName];
    
    if ([elementName isEqualToString:@"status"]) {
        // Make new entry in parsedObjects.
        NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
        [parsedObjects addObject:newNode];
		currentNode = newNode;
		
    } else if ([elementName isEqualToString:@"user"]) {
        // Add a 'user' dictionary to current node.
        NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
        [currentNode setObject:newNode forKey:elementName];
        currentNode = newNode;
    } else if (currentNode) {
        // Create relevant name-value pair.
        [currentNode setObject:[NSMutableString string] forKey:elementName];
    }
}
Would I use Regex to parse the information before it adds the object? Or can the XML parser go one step further and parse that phrase before it's added?

Thanks!
tmoney11 is offline   Reply With Quote
Old 12-15-2010, 02:54 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 5
Benoit Caccinolo is on a distinguished road
Default easily convert XML to NSDictionary

To easily convert XML to NSDictionary, here is a little lib to do this conversion:

XML to NSDictionary Converter bcaccinolo's blog

The code is on Github.

Cheers,
Benoit Caccinolo is offline   Reply With Quote
Reply

Bookmarks

Tags
parse, twitter, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 326
22 members and 304 guests
baja_yu, cgokey, chemistry, Domele, Duncan C, Fstuff, gbenna, givensur, guusleijsten, heshiming, HowEver, iAppDeveloper, iphonedevshani, jbro, JoeRCruso, mdpauley, n00b, newDev, seokwon lee, SLIC, stanny, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,874
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:31 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0