2
다음은 구문 분석하려는 기본 설정을 보여주는 샘플 XML입니다.노드 내의 노드에 액세스하는 방법 GDataXML
지금까지는 작업, 작업, 제목, 힌트, 운동 및 텍스트에 대한 데이터를 추출 할 수 있었고 운동시 속성 type
을 움켜 쥘 수있었습니다.
그러나 나는 내 인생에서 태그 질문을 포함하는 질문 블록을 얻는 방법을 알아낼 수 없습니다.
이-(void)createTask
{
self.task = [[Task alloc] init];
// grab the task from the loaded xml
NSArray *tasks = [[AppData sharedInstance].XMLTaskDocument.rootElement elementsForName:@"task"];
// cycle through the task and extract its data assigning to appropriate model property
for (GDataXMLElement *task in tasks)
{
NSString *title = nil;
NSArray *titles = [task elementsForName:@"title"];
if ([titles count] > 0)
{
GDataXMLElement *firstTitle = (GDataXMLElement *)[titles objectAtIndex:0];
title = firstTitle.stringValue;
} else continue;
NSString *hint = nil;
NSArray *hints = [task elementsForName:@"hint"];
if ([hints count] > 0)
{
GDataXMLElement *firstHint = (GDataXMLElement *)[hints objectAtIndex:0];
hint = firstHint.stringValue;
} else continue;
NSString *type = nil;
NSString *text = nil;
NSArray *exercises = [task elementsForName:@"exercise"];
if ([exercises count] > 0)
{
type = [(GDataXMLNode *)[[exercises objectAtIndex:0] attributeForName:@"type"] stringValue];
GDataXMLElement *firstText = (GDataXMLElement *)[exercises objectAtIndex:0];
text = firstText.stringValue;
// THIS DOES NOT WORK :-(
NSArray *questions = [task elementsForName:@"questions"];
if ([questions count] > 0)
{
NSLog(@"questions count is: %d", [questions count]);
}
} else continue;
}
}
사람이 질문을 잡아하는 방법을 희망 말해 줄 수 : 내가 지금까지 데이터를 얻을 방법은 다음과
<?xml version="1.0" encoding="UTF-8" ?>
<tasks>
<task>
<title>Any ole text goes here</title>
<hint>dont cross busy roads!</hint>
<exercise type="yes_no">
<text>which planet is nearest the sun?</text>
<questions>
<question answer="false">Mars</question>
<question answer="true">Mercury</question>
<question answer="false">Saturn</question>
</questions>
</exercise>
</tasks>
이야?
몇 가지 이유 때문에 여기에 나타나는 샘플 xml을 가져올 수 없으므로 처음 몇 줄을 제거하는 것처럼 보입니까? – user7865437