This is a xml structure that I want to parse using libxml parsing.


How can i get the attribute value for "campaign" tag i.e ID and for the "image" tag i.e url and size.
If I use these values, i can extract the values of "code" tag and "name " tag.
static const char *kName_campaign = "campaign";
static const NSUInteger kLength_campaign = 9;
static const char *kName_code = "code";
static const NSUInteger kLength_code = 5;
static const char *kName_name = "name";
static const NSUInteger kLength_name = 5;
Then I get the code and name of current and upcoming campaign all together.
This is the code I use in the delegate which gets called when parsing is done.
static void endElementSAX(void *ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI)
{
LibXMLParser *parser = (LibXMLParser *)ctx;
if (parser.parsingASong == NO) return;
if (prefix == NULL)
{
if (!strncmp((const char *)localname, kName_campaign, kLength_campaign))
{
[parser finishedCurrentSong];
parser.parsingASong = NO;
}
else if (!strncmp((const char *)localname, kName_code, kLength_code))
{
parser.currentSong.title = [parser currentString];
NSLog(@"Code :: %@",[parser currentString]);
}
else if (!strncmp((const char *)localname, kName_name, kLength_name))
{
parser.currentSong.category = [parser currentString];
NSLog(@"Name :: %@",[parser currentString]);
}
}
}
How can i get the attributes values from start to bottom of id from "campaign" tag. url and size from "image" tag?
Try this..