Attribute libxml2 xpath howto:
Given the xml:
<yournodewithanattribute someattribute="some attribute value"></yournodewithanattribute>
To get the attribute value:
NSString *path = [NSString stringWithFormat:@"http://yourdomain/yourxmlfile.xml"];
NSURL *url = [NSURL URLWithString:path];
NSData *xmlData = [NSData dataWithContentsOfURL:url];
NSString *xPathQuery1;
NSArray *nodes1;
xPathQuery1 = @"//yournodewithanattribute";
nodes1 = (NSArray*)PerformXMLXPathQuery(xmlData, xPathQuery1);
for (NSDictionary *attrNodes1 in nodes1){
for (NSDictionary *nodeAttributeArray in [attrNodes1 objectForKey:@"nodeAttributeArray"]){
NSString *attributeName = [nodeAttributeArray objectForKey:@"attributeName"];
NSString *attributeValue = [nodeAttributeArray objectForKey:@"nodeContent"];
NSLog(@"Attribute Name: %@", attributeName);
NSLog(@"Attribute Value: %@", attributeValue);
}
}
No comments:
Post a Comment