Skip to content
Newer
Older
100644 143 lines (100 sloc) 3.98 KB
dc5be1c Initial check-in.
uli authored
1 //
2 // NSDictionary+XMLPersistence.m
3 // TestPadDataReader
4 //
5 // Created by Uli Kusterer on 07.10.04.
720b0e7 @uliwitness Added licensing information to the source files.
authored
6 // Copyright (c) 2004 M. Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
dc5be1c Initial check-in.
uli authored
26 //
27
28 #import "NSDictionary+XMLPersistence.h"
29 #import "UKXMLPersistence.h"
30
31
32 @implementation NSDictionary (UKXMLPersistence)
33
34 +(id) dictionaryWithXML: (NSString*)str arrayKeys: (NSString**)arr
35 {
36 return [(id) UKCreateDictionaryFromXML( (CFStringRef) str, (CFStringRef*)arr, kUKXMLCreateDictionaryDefaultFlags ) autorelease];
37 }
38
39
40 +(id) dictionaryWithXML: (NSString*)str
41 {
42 return [(id) UKCreateDictionaryFromXML( (CFStringRef) str, NULL, kUKXMLCreateDictionaryDefaultFlags ) autorelease];
43 }
44
45
46 +(id) dictionaryWithXML: (NSString*)str flags: (unsigned int)flags
47 {
48 return [(id) UKCreateDictionaryFromXML( (CFStringRef) str, NULL, flags ) autorelease];
49 }
50
51
52
53 +(id) dictionaryWithXMLData: (NSData*)data
54 {
55 NSString* xml = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
56 return [self dictionaryWithXML: xml];
57 }
58
59
60 +(id) dictionaryWithXMLData: (NSData*)data arrayKeys: (NSString**)arr
61 {
62 NSString* xml = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
63 return [self dictionaryWithXML: xml arrayKeys: arr];
64 }
65
66
67 +(id) dictionaryWithXMLData: (NSData*)data flags: (unsigned int)flags
68 {
69 NSString* xml = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
70 return [self dictionaryWithXML: xml flags: flags];
71 }
72
73
74
75 +(id) dictionaryWithContentsOfXMLFile: (NSString*)path
76 {
77 NSString* str = [NSString stringWithContentsOfFile: path];
78
79 return [self dictionaryWithXML: str];
80 }
81
82
83 +(id) dictionaryWithContentsOfXMLFile: (NSString*)path arrayKeys: (NSString**)arr
84 {
85 NSString* str = [NSString stringWithContentsOfFile: path];
86
87 return [self dictionaryWithXML: str arrayKeys: arr];
88 }
89
90
91 +(id) dictionaryWithContentsOfXMLFile: (NSString*)path flags: (unsigned int)flags
92 {
93 NSString* str = [NSString stringWithContentsOfFile: path];
94
95 return [self dictionaryWithXML: str flags: flags];
96 }
97
98
99 -(NSString*) xmlRepresentation
100 {
101 return [(NSString*) UKCreateXMLFromDictionary( (CFDictionaryRef) self, kUKXMLCreateXMLDefaultFlags ) autorelease];
102 }
103
104
105 -(NSString*) xmlRepresentationWithFlags: (unsigned int)flags
106 {
107 return [(NSString*) UKCreateXMLFromDictionary( (CFDictionaryRef) self, flags ) autorelease];
108 }
109
110
111 -(NSData*) xmlData
112 {
113 NSString* str = [(NSString*) UKCreateXMLFromDictionary( (CFDictionaryRef) self, kUKXMLCreateXMLDefaultFlags ) autorelease];
114 return [str dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion: YES];
115 }
116
117
118 -(NSData*) xmlDataWithFlags: (unsigned int)flags
119 {
120 NSString* str = [(NSString*) UKCreateXMLFromDictionary( (CFDictionaryRef) self, flags ) autorelease];
121 return [str dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion: YES];
122 }
123
124
125
126
127 -(BOOL) writeToXMLFile: (NSString*)path atomically: (BOOL)atm
128 {
129 NSString* str = [self xmlRepresentation];
130
131 return [str writeToFile: path atomically: atm];
132 }
133
134
135 -(BOOL) writeToXMLFile: (NSString*)path atomically: (BOOL)atm flags: (unsigned int)flags
136 {
137 NSString* str = [self xmlRepresentationWithFlags: flags];
138
139 return [str writeToFile: path atomically: atm];
140 }
141
142
143 @end
Something went wrong with that request. Please try again.