Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: XML



Hi Steve,

I did the same thing recently, and it took a bit of trial and error to get things working - but in the end it was quite easy. I used CFPropertyList to do the work. Below is some code to get you cracking (I'm sure you can fill in the blanks). I hope it helps!

OSStatus err = noErr;
FSRef myFSRef;
CFURLRef myURLRef = NULL;
CFMutableDataRef myDataRef = CFDataCreateMutable (kCFAllocatorDefault, 0);
CFPropertyListRef myPropertyListRef = NULL;
CFStringRef errorString = NULL;
SInt16 forkRefNum = -1;
SInt64 countOfBytes = 0;
void* rawBytePtr = NULL;
CFStringRef configProdCodeRef = NULL;
CFIndex configFileDictCount = 0;
CFIndex i = 0;


err = FSOpenFork(&myFSRef, 0, NULL, fsRdPerm, &forkRefNum );
if (!err)
err = FSGetForkSize( forkRefNum, &countOfBytes );
if (!err)
rawBytePtr = malloc(countOfBytes);

if (rawBytePtr)
{
err= FSReadFork(forkRefNum, fsFromStart, 0, countOfBytes, rawBytePtr, NULL);
if (!err)
CFDataAppendBytes (myDataRef, (const unsigned char*) rawBytePtr, countOfBytes);

FSCloseFork(forkRefNum);

myPropertyListRef = CFPropertyListCreateFromXMLData (kCFAllocatorDefault, myDataRef,
kCFPropertyListImmutable, &errorString);

if (errorString)
CFRelease(errorString);


	free(rawBytePtr);
}
if (myURLRef)
	CFRelease(myURLRef);

// This code copies each key/value pair from my configuration file to the user's preferences
if (myPropertyListRef)
{
configFileDictCount = CFDictionaryGetCount((CFDictionaryRef) myPropertyListRef);
const void** keys = (const void **)malloc (sizeof(void *) * configFileDictCount);
const void** values = (const void **)malloc (sizeof(void *) * configFileDictCount);
CFDictionaryGetKeysAndValues((CFDictionaryRef) myPropertyListRef,(const void**)keys,(const void**)values);

for (i = 0; i < configFileDictCount; i++)
CFPreferencesSetAppValue((CFStringRef) keys[i], (CFStringRef) values[i], CFSTR(kApplicationID));

CFPreferencesAppSynchronize(CFSTR(kApplicationID));

if (keys)
free(keys);
if (values)
free(values);
}


brian
**************************
Brian M. Criscuolo
DataViz, Inc. Engineering
email@hidden
203.874.0085 x3065

Date: Mon, 15 Nov 2004 17:25:03 -0600
From: "Steve Mills" <email@hidden>
Subject: XML
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed

I've read the docs and I just don't understand. How can I take a .plist
file, read and parse it, then iterate through each element? The .plist
root is an array, each element in the array is a dictionary. Somewhere
in the docs it illustrates how to use CFXMLTreeCreateFromData, but the
resulting tree was nil. I'm totally confused about all the nodes and
trees and property lists. Anybody have some sample source?

_________________________________________________________
Steve Mills                              Me: 952-401-6255
Senior Software Architect                         MultiAd
email@hidden                       www.multi-ad.com

_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.