I have been trying to send data down in xml format to the iphone. But I just cannot get the array to properly work. NSLog keeps returning null. What should I do to correct this?
<?php
...(mysql query)
$q = $dbh->prepare( $sql );
$doc = new DOMDocument();
$r = $doc->createElement( "oneam" );
$doc->appendChild( $r );
foreach ( $q->fetchAll() as $row) {
$e = $doc->createElement( "location" );
$e->setAttribute( 'its', $row['oneam']);
$r->appendChild( $e );
}
print $doc->saveXML();
?>
My Xcode for a view controller
- (void)viewDidLoad
{
[super viewDidLoad];
char *cStr = "YES";
NSString *str3 = [NSString stringWithUTF8String:cStr];
NSString *urlString = [NSString stringWithFormat:@"(censored)", _login];
NSXMLParser *Parser = [[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];
[Parser setDelegate:self];
[Parser parse];
if (([[oneam objectForIndex:@"its" ]isEqualToString:@"YES" ])) {
[switch1 setOn:YES animated:YES];
}
else {
[switch1 setOn:NO animated:YES];
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ( [elementName isEqualToString:@"location"]) {
[oneam addObject:[[NSDictionary alloc] initWithDictionary:attributeDict]];
NSLog(@"The array is %@", oneam);
}
}
In your
viewDidLoadwrite the following code:You are not allocating the array, that’s why it is null.