NSDictionary
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>arrayKey</key>
<array>
<string>string1</string>
<string>string2</string>
<string>string3</string>
<string>string4</string>
</array>
<key>dicKey</key>
<dict>
<key>key1</key>
<string>object1</string>
<key>key2</key>
<string>object2</string>
<key>key3</key>
<string>object3</string>
</dict>
<key>key2</key>
<string>object2</string>
<key>key3</key>
<string>object3</string>
</dict>
</plist>
NSArray
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>string1</string>
<string>string2</string>
<string>string3</string>
<dict>
<key>key1</key>
<string>object1</string>
<key>key2</key>
<string>object2</string>
<key>key3</key>
<string>object3</string>
</dict>
<string>string5</string>
</array>
</plist>
At the end, after </plist>, there’s another CR.
example NSArray NSDIctionary plist xml
490‘Initial interface orientation’ setting in Info.plisy
246writeToFile – quick file writing
243Stepping over an Array (or Dictionary)
220Linking libxml2 in Xcode
214NSMutableArray: setObject vs. setValue
How to link libxml2 in Xcode for use with TouchXML?
1. Copy TouchXML files. They are wrappers to libxml2.
2. Instead of copying an extra copy of libxml2 to the project frameworks, add the following to the target information:
Header Search Paths:
Other Linker Flags:
(Of course assuming, that libxml2 is present at this location on your system.)
In the Target Info, make sure to select the current configuration to see the values. Otherwise you get <Multiple Values> and they look like it’s not possible to edit them. Took me a while to figure out, that changing the configuration [top left] was the key. Duh.
libxml2 link Multiple Values TouchXML Xcode xml
576NSDictionary and NSArray plist examples
379Never use a beta SDK for active development
365Project templates for PyObjC and RubyCocoa
275UIWebView – checking when user clicks a link
214NSMutableArray: setObject vs. setValue
Following situation Using TouchXML to parse XML data, works without problem on example XML files, but crahes on mine.
Problem Empty values in my data set. (sometimes <place>somePlace</place>, sometimes <place></place>)
/* CXMLDocument setup & parsing omitted */
NSString *e = [[resultElement childAtIndex:counter] stringValue];
NSString *k = [[resultElement childAtIndex:counter] name];
[blogItem setObject:e forKey:k];
// crashes when e is empty. Displays a (null), is nil
Solution 1
Check for empty e, replace nil with empty string
// check if element is empty
if ( nil == e ) { // ...or the less elegant (0 == [e length])
e = @"";
}
[blogItem setObject:e forKey:k];
Solution 2
Use setValue instead of setObject, as setObject crashes and burns when it encounters nil, whereas setValue specifically deals only with strings and handles nil gracefully.
[blogItem setValue:e forKey:k];
nil NSMutableArray Objective-C setObject setValue xml
583UIAlertViews additional Buttons
576NSDictionary and NSArray plist examples
569Layering one UIImage onto of another UIImage
560#import vs #include in Objective C – A quick reminder
457Singleton Classes and Shared Resources in Objective-C
NSXMLParser parses XML, reports when each node ends, better for very, very large documents.
libxml2 loads whole xml file into memory.
http://code.google.com/p/touchcode/wiki/TouchXML
http://code.google.com/p/kissxml/
iPhone SDK Development by Bill Dudney and Chris Adamson
NSXMLParser
initWithContentsOfURL: may block GUI while downloading, can not handle HTTP authentication.
initWithData: accumulate data with NSURLConnection’s delegate -didReceiveResponse, -didReceiveData, -connectionDidFinishLoading.
TouchXML
- copy TouchXML files to project
- in “Targets”, select target > Get Info > add /usr/include/libxml2 to Header Search Paths
- add libxml2.dylib to “Frameworks”
UPDATE
instead of adding libxml2.dylib link to the Framework on the system:
Other Linker Flags:
Linking libxml2 in Xcode
libxml2 NSXMLParser xml
576NSDictionary and NSArray plist examples
220Linking libxml2 in Xcode
214NSMutableArray: setObject vs. setValue