Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the xml code I would use:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;elements&gt; &lt;element id="1" catname="Birthday" iid="1" subcatname="card1" url="http://www.orkutpapa.com/scraps/happy-birthday-card-2-3.jpg" /&gt; &lt;/elements&gt; </code></pre> <p>Using an XML format above, 'elements' contains all of your xml records. 'element' represents one record with the following variables: id, catname, iid, subcatname, and url. You can change these to your preference, but pay attention to these variable names. This is how you will call the data when parsing.</p> <p>You need to make a NSURLConnection somewhere. For example, this can be in response to a UITouch or placed in viewWillAppear. I am going to assume that you know how to make this connection, but it should contain the following methods:</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response </code></pre> <p>This method should reset the data because a incomplete response was received.</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data </code></pre> <p>This method is were you can append your data to an NSMutableData</p> <pre><code>- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error </code></pre> <p>This should handle errors, release the connection, and release the NSMutableData.</p> <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection </code></pre> <p>This method should call startParsingData and release the conneciton.</p> <p>Now for the part you are probably interested in (sorry if you knew the NSURLConnection references above), how to parse the data:</p> <pre><code>- (void)startParsingData { NSXMLParser *myDataParser = [[NSXMLParser alloc] initWithData:receivedFriendData]; myDataParser.delegate = self; [myDataParser parse]; [myDataParser release]; [myNSMutableData release]; } </code></pre> <p>In this method, you should initialize the data parser and assign the delegate. Make sure you assign the NSXMLParserDelegate protocol to your class.</p> <pre><code>- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"element"]) { NSString *url = [NSString stringWithFormat:@"%@", [attributeDict objectForKey:@"url"]]; // Now do with your URL as you please =) } } </code></pre> <p>Notice that attributeDict calls objectForKey. This key should match the variable name in the xml file that you want to call and use. Also notice that elementName ('element') matches the record name in the xml file. </p> <p>Let me know if this helps or if you have any additional questions! </p> <p>Cheers, Evan</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload