 |
 |
XML Parsing classes?
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
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!
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
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 
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum 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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|