Permalink
Browse files

(split)TouchXML docs

--HG--
rename : TouchXML/README.txt => TouchXML/README.markdown
  • Loading branch information...
1 parent a31918e commit cbfc6937953710706c33d9e95903edd0707152cd @schwa schwa committed Apr 21, 2010
View
BIN Documentation/1-header-search-paths.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Documentation/2-other-linker-flags.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Documentation/3-add-existing-files.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Documentation/4-select-everything.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Documentation/5-confirm.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
69 Documentation/Installing.markdown
@@ -0,0 +1,69 @@
+(Originally from [http://foobarpig.com/iphone/touchxml-installation-guide.html][1], reused with kind permission of author.)
+
+# TouchXML installation guide
+
+TouchXML is a libxml API wrapper written in Objective-C and usually helps with all your project XML needs. While writing my post about parsing XML element attributes and putting up demo project I realized that I tend to forget how to add TouchXML to new project, so here goes step-by-step of that procedure:
+
+1. Get TouchXML
+
+ You can find archives to download in touchcode project downloads . Download TouchXML archive and extract it anywhere you like. It’s common practice to keep such libraries and classes in *Developer/ExtraLibs* directory.
+
+2. Enable *libxml2* library
+
+ First things first, before we actually add TouchXML files, we need to do some project configuration changes, so our project could use libxml library.
+
+ 1. Go to “Project -> Edit project settings”
+
+ 2. Activate “Build” tab
+
+ 3. Search for “Header search paths” setting and add */usr/include/libxml2* value to it
+
+ ![Image One][IMAGE_1]
+
+ 4. Search for “Other linker flags” setting and add *-lxml2* value
+
+ ![Image Two][IMAGE_2]
+
+ P.s. notice that search function is really useful for finding settings you need faster.
+
+3. Add TouchXML classes
+
+ 1. Right click (option click) on your projects “Classes” folder and go to “Add -> Existing files…”
+
+ ![Image Three][IMAGE_3]
+
+ 2. Navigate to the directory where extracted TouchXML is kept and browse deeper to “Common -> Source”. Select everything! And click “Add” obviously.
+
+ ![Image Four][IMAGE_4]
+
+ 3. Confirm.
+
+ ![Image Five][IMAGE_5]
+
+ Now you should see a bunch of new files in your project. I usually group them by selecting files I wish to group and then selecting “Group” in context (right click/option click) menu.
+
+4. Import TouchXML to your project
+
+ #import "TouchXML.h"
+
+ That is all the “magic” and you’re good to go. Since, I am not going to write about actually using TouchXML, you can see a nice working example in my [previous post][2].
+
+5. Common errors
+
+ Error: libxml/tree.h: No such file or directory
+
+ … and hundreds of something missing errors. It means that something went wrong with “Header search paths”. Maybe you didn’t added */usr/include/libxml2* or added incorrectly? Check it.
+
+ Error: “_xmlDocDumpFormatMemory”, referenced from:- [CXMLDocument description] in CXMLDocument.o
+
+ … and tens of errors like this. While errors by them selfs aren’t very expressive, they wish to inform you, that you did not added *-lxml2* flag to “Other linker flags”
+
+And that is all for now!
+
+[1]: http://foobarpig.com/iphone/touchxml-installation-guide.html
+[2]: http://foobarpig.com/iphone/parsing-xml-element-attributes-with-touchxml.html
+[IMAGE_1]: 1-header-search-paths.png
+[IMAGE_2]: 2-other-linker-flags.png
+[IMAGE_3]: 3-add-existing-files.png
+[IMAGE_4]: 4-select-everything.png
+[IMAGE_5]: 5-confirm.png
View
68 Documentation/TouchXMLParsing.markdown
@@ -0,0 +1,68 @@
+(Originally from [http://foobarpig.com/iphone/parsing-xml-element-attributes-with-touchxml.html][1], reused with kind permission of author.)
+
+Parsing XML element attributes with TouchXML
+Assuming that you already familiar with parsing XML with a little help from TouchXML we will go straight to the topic: parsing an attribute! I’ll just put some “sample” XML here so it would be easier to understand what’s happening in code later.
+
+ <pigletlist>
+ <piglet id="1">
+ <name>Nifnif</name>
+ </piglet>
+ <piglet id="2">
+ <name>Nufnuf</name>
+ </piglet>
+ <piglet id="3">
+ <name>Nafnaf</name>
+ </piglet>
+ </pigletlist>
+
+Well, here we have our tree little piglets put in a single XML file and bellow lies the magic code which parses piglet list with their id attributes. If you are too lazy to look trough all the code (I would be), key point is attributeForName method of CXMLElement object used like this: [[node attributeForName:@"id"] stringValue].
+
+ // we will put parsed data in an a array
+ NSMutableArray *res = [[NSMutableArray alloc] init];
+
+ // using local resource file
+ NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"piglets.xml"];
+ NSData *XMLData = [NSData dataWithContentsOfFile:XMLPath];
+ CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
+
+ NSArray *nodes = NULL;
+ // searching for piglet nodes
+ nodes = [doc nodesForXPath:@"//piglet" error:nil];
+
+ for (CXMLElement *node in nodes) {
+ NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
+ int counter;
+ for(counter = 0; counter < [node childCount]; counter++) {
+ // common procedure: dictionary with keys/values from XML node
+ [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
+ }
+
+ // and here it is - attributeForName! Simple as that.
+ [item setObject:[[node attributeForName:@"id"] stringValue] forKey:@"id"]; // <------ this magical arrow is pointing to the area of interest
+
+ [res addObject:item];
+ [item release];
+ }
+
+ // and we print our results
+ NSLog(@"%@", res);
+ [res release];
+
+Our results:
+
+ 2010-02-05 09:54:01.078 demo[1901:207] (
+ {
+ id = 1;
+ name = Nifnif;
+ },
+ {
+ id = 2;
+ name = Nufnuf;
+ },
+ {
+ id = 3;
+ name = Nafnaf;
+ }
+ )
+
+[1]: http://foobarpig.com/iphone/parsing-xml-element-attributes-with-touchxml.html
View
0 README.txt → README.markdown
File renamed without changes.

0 comments on commit cbfc693

Please sign in to comment.