【发布时间】:2026-01-24 19:20:18
【问题描述】:
我正在尝试使用 GdataxmlNode 目标 c 库解析一个巨大的 xml 文档(描述 3d 模型)。
这是一个阻碍我的 XML 示例:
<library_effects>
<effect name="Love_Love-fx" id="Love_Love-fx">
<profile_COMMON>
<newparam sid="sexy-surface">
<surface type="2D">
<init_from>sexy</init_from>
<format>A8R8G8B8</format>
</surface>
</newparam>
....
</profile_COMMON>
</effect>
....
</library_effects>
我的目标:
获取效果名称 (*Love_Love-fx*):完美运行
获取 init_from (sexy) 的内容:根本不起作用
我是这样解析的:
xmlGetData = [xmlDoc.rootElement elementsForName:@"library_effects"];
//Effects infos
int eff_c;
NSMutableArray *eff_ids = [[NSMutableArray alloc] init]; //effect names
NSMutableArray *eff_src = [[NSMutableArray alloc] init]; //efects sources
for (GDataXMLElement *e in xmlGetData)
{
eff_c = [[e elementsForName:@"effect"]count];
NSArray *eff_node = [e elementsForName:@"effect"];
for (int i = 0; i < eff_c; i++)
{
//get the effect name (id & name are the same)
[eff_ids addObject:[[eff_node objectAtIndex:i]attributeForName:@"id"]];
//get the content of init_from
[eff_src addObject:[[eff_node objectAtIndex:i]elementForName:@"init_from"]];
}
}
我的问题:
我在最后一行 ([eff_src addObject.........) 上有一个 SIGABRT,所以我无法获取“init_from”的内容
(因为[[eff_node objectAtIndex:i]elementForName:@"init_from"]] 返回 Nil。?)
有人可以帮帮我吗? (有没有清晰完整的文档?我只看到博客文章解释了其中的一部分)
恶心的解决方案:
使用[[[[[[eff_node objectAtIndex:i]childAtIndex:0]childAtIndex:0]childAtIndex:0]childAtIndex:0]stringValue];
【问题讨论】:
标签: objective-c xml-parsing gdata