Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > XML Parsing classes?

XML Parsing classes?
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 17, 2002, 02:56 PM
 
Are there any Cocoa classes for parsing XML data? Specifically, I have a database that returns results in XML format and I would like to extract the data from a field. I guess I am just looking for a class that will find the tags for a field and extract the data from between the tags into an NSString or or NSMutableArray.

kman
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Mar 17, 2002, 04:09 PM
 
None that are built into the OS, I'm afraid. However, you can use CoreFoundation's XML services to get the data out.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 17, 2002, 06:33 PM
 
Isn't CoreFoundation Carbon?

I guess it won't be that hard to write a function to step through the data looking for tags. That will be next weekends project unless I can find some existing code on the net in the meantime.

kman
     
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Mar 17, 2002, 07:09 PM
 
Isn't CoreFoundation Carbon?
Yes, it is. That doesn't matter. Anytime you link against Cocoa, Carbon is being included, and so you're free to use any Carbon API.

Writing an Objective-C wrapper around CFXML would be a nice simple project. (Though, since I hear that 10.2 will include some sort of XML-persistence magic associated with NSCoder, we might get some decent XML classes soon).

You might also look into Objective-XML.
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 18, 2002, 01:59 AM
 
CoreFoundation is neither Cocoa nor Carbon. It's a layer below both of them, in a way. CoreFoundation APIs (and the many other CF-based APIs on Mac OS X) are plain C, but they have a sort of object-oriented design that's almost like Cocoa. (Not surprising, since the CF team at Apple has a lot of guys who worked on Foundation for OPENSTEP/Cocoa.) In fact, much of Cocoa's Foundation framework is now based on CoreFoundation, and you can cast freely between Foundation classes (like NSString) and CoreFoundation types (like CFString). Since Foundation is based on CF, the CF headers are automatically included in your Cocoa projects and ready to be used.

If CFXML doesn't do everything you need, you might also check out our Omni Expat framework, available here. It's an Obj-C wrapper for the powerful open-source XML parser expat; we currently use it for storing OmniWeb's cookies in a custom XML format, and we'll probably be using it for more in the future.
Rick Roe
icons.cx | weblog
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Mar 18, 2002, 02:49 PM
 
Originally posted by Rickster:
<STRONG>CoreFoundation is neither Cocoa nor Carbon. It's a layer below both of them, in a way. CoreFoundation APIs (and the many other CF-based APIs on Mac OS X) are plain C, but they have a sort of object-oriented design that's almost like Cocoa. </STRONG>
Actually, CoreFoundation is part of CarbonLib on OS 9, which is why people are often confused
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 21, 2002, 09:00 PM
 
Originally posted by Rickster:
<STRONG>CoreFoundation is neither Cocoa nor Carbon. It's a layer below both of them, in a way. CoreFoundation APIs (and the many other CF-based APIs on Mac OS X) are plain C, but they have a sort of object-oriented design that's almost like Cocoa. (Not surprising, since the CF team at Apple has a lot of guys who worked on Foundation for OPENSTEP/Cocoa.) In fact, much of Cocoa's Foundation framework is now based on CoreFoundation, and you can cast freely between Foundation classes (like NSString) and CoreFoundation types (like CFString). Since Foundation is based on CF, the CF headers are automatically included in your Cocoa projects and ready to be used.

If CFXML doesn't do everything you need, you might also check out our Omni Expat framework, available here. It's an Obj-C wrapper for the powerful open-source XML parser expat; we currently use it for storing OmniWeb's cookies in a custom XML format, and we'll probably be using it for more in the future.</STRONG>
I downloaded this per your suggestion and perused it for an hour or so. It went a bit over my head. Will one of these classes let me pass it the file and the element I want to extract and then return the data in the element? I apologize for my incredible ignorance.

kman
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Mar 22, 2002, 02:19 PM
 
Originally posted by kman42:
<STRONG>I downloaded this per your suggestion and perused it for an hour or so. It went a bit over my head. Will one of these classes let me pass it the file and the element I want to extract and then return the data in the element? I apologize for my incredible ignorance.</STRONG>
I think CoreFoundation might be easier, and will mean that you won't have to distribute the Omni frameworks with your app.
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Mar 24, 2002, 12:23 PM
 
Well, here is my incredibly simple solution to my simple problem:
#import "XMLParser.h"


@implementation XMLParser
+(NSString *)parse: (NSString *)stringToBeParsed withBeginningTag NSString *)beginningTag withEndingTag: (NSString *)endingTag
{
NSScanner *theScanner;
NSString *parseResults;

theScanner = [NSScanner scannerWithString:stringToBeParsed];
[theScanner scanUpToString:beginningTag intoString:NULL];
[theScanner scanString:beginningTag intoString:NULL];
[theScanner scanUpToString:endingTag intoString:&parseResults];
return parseResults;
}
@end
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 12:21 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2