// ---------------------------------
// save a property list into an XML file:
SInt32 SavePropertiesToXMLFile(
const CFPropertyListRef pCFPRef,
const CFURLRef pCFURLRef)
{
CFDataRef xmlCFDataRef;
SInt32 errorCode = coreFoundationUnknownErr;
// Convert the property list into XML data.
xmlCFDataRef = CFPropertyListCreateXMLData(
kCFAllocatorDefault, pCFPRef );
if (NULL != xmlCFDataRef)
{
// Write the XML data to the file.
(void) CFURLWriteDataAndPropertiesToResource(
pCFURLRef, xmlCFDataRef, NULL, &errorCode);
// Release the XML data
CFRelease(xmlCFDataRef);
}
return errorCode;
}
// ---------------------------------
// load a property list from an XML file
CFPropertyListRef CreatePropertiesFromXMLFile(const CFURLRef pCFURLRef)
{
CFDataRef xmlCFDataRef;
CFPropertyListRef myCFPropertyListRef = NULL;
Boolean status;
// Read the XML file.
status = CFURLCreateDataAndPropertiesFromResource(
kCFAllocatorDefault, pCFURLRef,
&xmlCFDataRef, NULL, NULL, NULL);
if (status)
{
// Reconstitute the dictionary using the XML data.
myCFPropertyListRef = CFPropertyListCreateFromXMLData(
kCFAllocatorDefault, xmlCFDataRef,
kCFPropertyListImmutable, NULL);
// Release the XML data
CFRelease(xmlCFDataRef);
}
return myCFPropertyListRef;
}
|