I am completely baffled by this as I have coded several other methods using TBXML to properly parse an XML file. Below is the method in question. The root element remains null no matter what I try therefore the rest of the method fails. As you can see, the XML file is located on the web being output via PHP. I've used this exact same method in another application with no trouble whatsoever. I've compared the XML output to what I previously used and see no differences other than elements. The code for this method is almost identical but I must be missing something. Any help would be greatly appreciated.
- (void)loadFromZenPhoto{
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:@"http://www.flpublicarchaeology.org/civilwar/generatexml.php"]];
// Obtain root element
TBXMLElement *root = tbxml.rootXMLElement;
// if root element is valid
if (root) {
TBXMLElement *site = [TBXML childElementNamed:@"site" parentElement:root];
// if a site element was found, create site object
while (site != nil) {
Site *aSite = [[Site alloc] init];
TBXMLElement *siteid = [TBXML childElementNamed:@"id" parentElement:site];
if (siteid != nil)
aSite.siteid = [[TBXML textForElement:siteid] intValue];
TBXMLElement *parentid = [TBXML childElementNamed:@"parentid" parentElement:site];
if (parentid != nil)
aSite.parentid = [[TBXML textForElement:parentid] intValue];
TBXMLElement *folder = [TBXML childElementNamed:@"folder" parentElement:site];
if (folder != nil)
aSite.folder = [TBXML textForElement:folder];
TBXMLElement *title = [TBXML childElementNamed:@"title" parentElement:site];
if (title != nil)
aSite.title = [TBXML textForElement:title];
// add site object to the sites array
[sites addObject:aSite];
//advance to next sibling
site = [TBXML nextSiblingNamed:@"site" searchFromElement:site];
}
}
}