我被困在尝试通过使用 libxml2 解析 iPhone 应用程序上的 api 来检测某些通用 xmls 中属性的名称和值对。对于我的项目,解析速度真的很重要,所以我决定使用 libxml2 本身而不是使用 NSXMLParser。
现在,作为 iPhone SDK 的示例 XMLPerformance,用于 NSXMLParser 和 libxml2 之间的解析基准测试,我试图在下面的 XML 解析器处理程序之一中获取属性的详细信息,但我不知道如何检测它.
/* for example, <element key="value" /> */
static void startElementSAX(void *ctx, const xmlChar *localname, const xmlChar *prefix,
const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, int nb_attributes,
int nb_defaulted, const xmlChar **attributes)
{
if (nb_attributes > 0)
{
NSMutableDictionary* attributeDict = [NSMutableDictionary dictionaryWithCapacity:(NSUInteger)[NSNumber numberWithInt:nb_attributes]];
for (int i=0; i<nb_attributes; i++)
{
NSString* key = @""; /* expected: key */
NSString* val = @""; /* expected: value */
[attributeDict setValue:val forKey:key];
}
}
}
我看到了 libxml2 文档,但我看不到。如果你是伟大的黑客,请帮助我:)