CFXML Solution
CFXML Solution
- Subject: CFXML Solution
- From: email@hidden
- Date: Wed, 12 Jun 2002 01:53:39 EDT
Since it is best to both give and receive, here is solution for my XML
Parsing question awhile back. Thanks to Don Briggs for source code, and Chris
Ridd for support.
To parse a given XML file, it is best to use the bundle to create the path to
file "something.xml". Use NSData's dataWithContentsOfFile to read the data
file in, and CURL's CFURLCreateWithFileSystemPath to create URL. Converting
the NS references to CF References, you can then call CFXMLTreeCreateFromData.
NSString* a_path;
NSBundle* a_main_bundle;
CFURLRef a_url;
NSData *a_xml_data;
CFXMLTreeRef a_xml_tree;
a_main_bundle = [NSBundle mainBundle];
a_path = [a_main_bundle pathForResource:@"something" ofType:@"xml"];
a_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
(CFStringRef)a_path, kCFURLPOSIXPathStyle, NO);
a_xml_data = [NSData dataWithContentsOfFile: a_path];
a_xml_tree = CFXMLTreeCreateFromData(kCFAllocatorDefault,
(CFDataRef)a_xml_data, a_url, kCFXMLParserAllOptions,
kCFXMLNodeCurrentVersion);
I had the wrong constant for path style (use kCFURLPOSIXPathStyle), and
used a different parser option (the documentation recommends
kCFXMLParserAllOptions for best results).
In near future, I am going to encapsulate all of this into an NS style
object, along with the code to parse the nodes into lists of strings and
objects.
Thanks
Steve Sheets
Midnight Mage Software
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.