08-24-2008, 05:43 AM
#1 (permalink )
New Member
Join Date: Aug 2008
Posts: 31
Working with XML (?)
Hi,
I am working on a project that parses some xml from a webpage.
Do anyone know of a good tutorial for parsing xml and using its elements in code ?
Thanks
08-24-2008, 05:53 AM
#2 (permalink )
Registered Member
Join Date: May 2008
Posts: 20
I found from AppleBlog
08-24-2008, 06:20 AM
#3 (permalink )
New Member
Join Date: Aug 2008
Posts: 31
Quote:
Originally Posted by
odbc2000
Thank you.
I heard some rumors that NSXML wasn't available on the iphone (Only on the simulator )
Is that true ?
08-24-2008, 07:20 AM
#4 (permalink )
Registered Member
Join Date: May 2008
Posts: 20
Quote:
Originally Posted by
bergetun
Thank you.
I heard some rumors that NSXML wasn't available on the iphone (Only on the simulator )
Is that true ?
It's not TRUE, NSXML is available both on the simulator and the device.
08-24-2008, 08:03 AM
#5 (permalink )
New Member
Join Date: Aug 2008
Posts: 31
Quote:
Originally Posted by
odbc2000
It's not TRUE, NSXML is available both on the simulator and the device.
Okay. Thanks for the help.
08-24-2008, 01:37 PM
#6 (permalink )
I live @ iDevKit.com
Join Date: Jul 2008
Posts: 142
Here is what is going on with NSXML:
NSXMLDocument has been removed from the SDK because it is processor intensive. NSXMLParser has been left over. If you try using NSXMLDocument on the simulator it will work fine because the simulator uses the standard Cocoa Foundation classes. But as soon as you build for the device NSXMLDocument will not function.
Max
08-25-2008, 01:49 AM
#7 (permalink )
New Member
Join Date: Aug 2008
Posts: 31
Quote:
Originally Posted by
mxweas
Here is what is going on with NSXML:
NSXMLDocument has been removed from the SDK because it is processor intensive. NSXMLParser has been left over. If you try using NSXMLDocument on the simulator it will work fine because the simulator uses the standard Cocoa Foundation classes. But as soon as you build for the device NSXMLDocument will not function.
Max
Thanks for the explanation.
08-25-2008, 05:49 PM
#8 (permalink )
New Member
Join Date: Aug 2008
Posts: 31
Hi again,
Can anyone please explain a bit more on this tutorial :
Parse XML to custom objects :
Atrexis Blog: iPhone - Parse XML to custom objects
What I don't understand how I can cast the XMLToObjectParser (myParser) to a Contact object array.
Lets say I want to loop trough the contacts and print all the lastName information.
Edit: Reading my own post, made me realize that I really have some more reading to do .. (hurry up Amazon)
Last edited by bergetun; 08-25-2008 at 05:52 PM .
08-25-2008, 06:11 PM
#9 (permalink )
Registered Member
Join Date: Aug 2008
Location: London
Posts: 21
You set the delegate. Then listen for three calls:
Code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
You also need an NSMutableArray, let's call it
textInProgress .
In didStartElement you just clear textInProgress to be an empty NSMutableArray.
In didEndElement you can check what the elementName is and act accordingly, using string as the part between the element beginning and end.
In foundCharacters just do something like this: [textInProgress appendString:string];
08-26-2008, 02:39 AM
#10 (permalink )
New Member
Join Date: Aug 2008
Posts: 31
Quote:
Originally Posted by
hypercrypt
You set the delegate. Then listen for three calls:
Code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
You also need an NSMutableArray, let's call it
textInProgress .
In didStartElement you just clear textInProgress to be an empty NSMutableArray.
In didEndElement you can check what the elementName is and act accordingly, using string as the part between the element beginning and end.
In foundCharacters just do something like this: [textInProgress appendString:string];
But when I browse the myParser with the "object browser" I see that myParser contains a NSCFArray with all my Contacts.
NSURL *url = [NSURL URLWithString: @"http://localhost/contacts.xml"];
XMLToObjectParser *myParser = [[XMLToObjectParser alloc] parseXMLAtURL:url toObject:@"Contact" parseError:nil];
Shoulnd't it be possible to cast this to a "normal" array and then I can work with it
11-11-2009, 06:36 PM
#11 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 2
TBXML
Check out
TBXML V1.2 for a super-fast, lightweight, easy to use XML parser!
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 285
21 members and 264 guests
2WeeksToGo , ADY , apatsufas , ckgni , dacapo , Dani77 , Fritzer , ghost , HDshot , headkaze , jakerocheleau , joeallenpro , masc2279 , mer10 , mystic.purple , objch , Rudy , tathaastu , themathminister , timle8n1 , Zool
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,878
Threads: 89,224
Posts: 380,732
Top Poster: BrianSlick (7,129)
Welcome to our newest member, olga2000