나는 트래버스하는 데 어려움을 겪고있는 XML 파일을 가지고있다. 나는 xcode를 처음 접하는 분께 알려 드릴 것입니다. 나는 여기에 또 다른 가이드를 따라 갔다 :iphone/xcode SDK TBXML을 통한 트래버스?
iPhone TBXML Looping And Parsing Data하지만 그것은 나를 위해 작동하지 않는 것 같습니다.
여기 내 XML 파일이다 : 나는 각 항목을 잡아 TBXML와이를 통과하기 위해 노력하고있어
<Locations action="Request" version="1.0">
<location>
<CompanyID>44502</CompanyID>
<CompanyName>Holiday Inn</CompanyName>
<Distance>3.58km/2.23miles</Distance>
<tabs>
<tab>General Information</tab>
<tab>Add Review</tab>
</tabs>
<Address>
<Address1>Holiday Inn Reading - South</Address1>
<Address2>500 Basingstoke Road</Address2>
<Address3/>
<PostTown>Reading</PostTown>
<County/>
<PostCode>RG2 0SL</PostCode>
</Address>
</location>
</Locations>
(나는 하나 그것을 할 나섰고을 반복 할 수 없었다).
.H 파일은 다음과 같습니다 나는 그 말에이 오류를 받고 있어요 그러나
@interface LoadXML : UIViewController {
IBOutlet UITableView *tblLoadXML;
NSMutableArray *records;
}
@property(nonatomic,retain)NSMutableArray *records;
-(void)loadRecords:(NSString *)records;
-(void)traverseElement:(TBXMLElement *)element;
@end
가`TBXMLElement 전에 ')를'유형을 예상하고 예상.
내하는 .m 파일은 다음과 같습니다 아마 매우 멍청한 짓을하고 있어요
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (Cell == nil) {
Cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
Cell.text = [records objectAtIndex:indexPath.row];
}
- (void)loadRecords:(NSString *)records {
NSString *someXML = @"http://de0937/directenquirieswebapplicationv3.0/mobilesearch/what/0/49424/342/0/Reading/Hotels%20and%20Inns/0/0/0/0/0/search.aspx";
TBXML *tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:someXML]] retain];
records = [NSMutableArray array];
[records retain];
if (tbxml.rootXMLElement)
[self traverseElement:tbxml.rootXMLElement];
[tbxml release];
}
- (void) traverseElement:(TBXMLElement *)element {
do {
if (element->firstChild)
[self traverseElement:element->firstChild];
if ([[TBXML elementName:element] isEqualToString:@"location"]) {
TBXMLElement *name = [TBXML childElementNamed:@"CompanyName" parentElement:element];
TBXMLElement *distance = [TBXML childElementNamed:@"Distance" parentElement:element];
TBXMLElement *id = [TBXML childElementNamed:@"ID" parentElement:element];
[records addObject:[NSArray arrayWithObjects:
[TBXML textForElement:name],
[TBXML textForElement:distance],
[TBXML textForElement:id],nil]];
}
} while ((element = element->nextSibling));
}
하지만, 그것은 나를 미치게입니다! 어떤 도움을 많이 주시면 감사하겠습니다.
--- 이것은 이전에 가지고 있던 것이며, 완벽하게 작동하지만 하나의 레코드에 대해서만 작동합니다. 기본적으로 난 할 노력하고있어 그래서 나는 배열로 각 항목을 넣어 의지를 꺼내 수있는이 변환입니다 : 오류를 바탕으로
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (Cell == nil) {
Cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
TBXML * XML = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.tomstest.info/ios/results.xml"]] retain];
TBXMLElement *rootXML = XML.rootXMLElement;
TBXMLElement *results = [TBXML childElementNamed:@"location" parentElement:rootXML];
TBXMLElement *WOEID = [TBXML childElementNamed:@"CompanyName" parentElement:results];
NSString *woeid = [TBXML textForElement:WOEID];
Cell.text = woeid;
return Cell;
}
안녕하세요. .m에서 가져 왔고 .h에서 아무것도 가져 오지 않았습니다. @class를 넣었습니다. 이제 컴파일됩니다. 하지만 SIGBRT 오류로 넘어지고 main.m에 중단 점을 넣습니다. retVal = UIApplicationMain (argc, argv, nil, nil); – TMB87
내 대답과 같은 소리가 도움이되었습니다. 당신은 아마 그것을 투표해야합니다. :-) 당신은 오류에 대해 더 많은 정보를 줄 수 있습니까? 스택 추적을 넣고 오류를 일으킨다. libz.dylib를 추가하는 것을 잊지 않으셨습니까? –
도움이 되었기 때문에 나는 투표 할 담당자를 두려워하지 않았다. 오류 : int retVal = UIApplicationMain (argc, argv, nil, nil); SIGBART 오류가있는 이 넘어졌습니다. 나는 그것이 약간의 청어라고 생각한다. 내가 내 일을 잘했는지 안다. 아가야? – TMB87