I got stuck on trying to detect the pair of name and value of the attributes in some general xmls by using libxml2 for parsing the api on iPhone application. For my project, the parsing speed is really important, so I decided to use libxml2 itself instead of using NSXMLParser.
Now, as referring to XMLPerformance that is a sample of iPhone SDK for the parsing benchmark between NSXMLParser and libxml2, I tried to get the detail of attribute in one of XML parser handler as below, but I don't know exactly how to detect it.
/* 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];
}
}
}
I saw the libxml2 document, but I can't. Please help me if you are great hacker :)