Iphone 如何访问节点中的节点
下面是一些示例XML,显示了我试图解析的基本设置 到目前为止,我可以轻松提取任务、任务、标题、提示、练习和文本的数据,并在练习中获取属性Iphone 如何访问节点中的节点,iphone,xml,parsing,gdataxml,Iphone,Xml,Parsing,Gdataxml,下面是一些示例XML,显示了我试图解析的基本设置 到目前为止,我可以轻松提取任务、任务、标题、提示、练习和文本的数据,并在练习中获取属性type 然而,在我的一生中,我无法弄清楚如何获得包含附加疑问句的问句块 <?xml version="1.0" encoding="UTF-8" ?> <tasks> <task> <title>Any ole text goes here</title> <hint&g
type
然而,在我的一生中,我无法弄清楚如何获得包含附加疑问句的问句块
<?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>
有人能告诉我如何抓住问题吗?你犯了一个小错误。您可以从任务根目录而不是练习根目录中调用'elementsForName:@“questions”。它不起作用,因为“问题”元素不存在于任务元素中,而只存在于练习元素中 解决方案应该是这样的:
// Replace this
NSArray *questions = [task elementsForName:@"questions"];
if ([questions count] > 0)
{
NSLog(@"questions count is: %d", [questions count]);
}
// By this
NSArray *questions = [[exercises objectAtIndex:0] elementsForName:@"questions"];
if ([questions count] > 0)
{
NSLog(@"questions count is: %d", [questions count]);
}
我希望它能对您有所帮助。由于某些原因,我无法在此处显示示例xml,因为它似乎删除了前几行??
// Replace this
NSArray *questions = [task elementsForName:@"questions"];
if ([questions count] > 0)
{
NSLog(@"questions count is: %d", [questions count]);
}
// By this
NSArray *questions = [[exercises objectAtIndex:0] elementsForName:@"questions"];
if ([questions count] > 0)
{
NSLog(@"questions count is: %d", [questions count]);
}