iPhoneアプリケーションでAPIを解析するためにlibxml2を使用して、いくつかの一般的なxmlの属性の名前と値のペアを検出しようとして立ち往生しました。私のプロジェクトでは、解析速度が非常に重要であるため、NSXMLParserを使用する代わりにlibxml2自体を使用することにしました。
さて、NSXMLParserとlibxml2の間の解析ベンチマーク用のiPhone SDKのサンプルであるXMLPerformanceを参照して、以下のようにXMLパーサーハンドラーの1つで属性の詳細を取得しようとしましたが、正確に検出する方法がわかりません。
/* 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ドキュメントを見ましたが、できません。あなたが素晴らしいハッカーなら私を助けてください:)