Skip to content

Instantly share code, notes, and snippets.

@mtsd
Last active December 26, 2015 04:49
Show Gist options
  • Select an option

  • Save mtsd/7096415 to your computer and use it in GitHub Desktop.

Select an option

Save mtsd/7096415 to your computer and use it in GitHub Desktop.
libxml2で属性(xsi:nil="true")を取得する
xmlNodePtr cur = ...;
/*****
(1)
*/
xmlChar *prop = xmlGetProp(cur, (const xmlChar *) "nil");
// xmlChar *prop = xmlGetNsProp(cur, (const xmlChar *) "nil", (const xmlChar *) "http://www.w3.org/2001/XMLSchema-instance");
NSLog(@"prop : %p", prop);
if (prop != NULL) {
NSString *value = [NSString stringWithCString:(char*)prop encoding:NSUTF8StringEncoding];
NSLog(@"value >>>>>>>>>> %@", value);
xmlFree(prop);
}
/*****
(2) = (1)
*/
const xmlChar *ret=NULL;
xmlAttrPtr prop = cur->properties;
while( prop ) {
if( xmlStrEqual( prop->name, (const xmlChar *) "xsi:nil" ) == 0 ) {
ret = prop->name;
break;
}
prop = prop->next;
}
if (ret != NULL) {
NSString *value = [NSString stringWithCString:(char*)ret encoding:NSUTF8StringEncoding];
NSLog(@"value >>>>>>>>>> %@", value);
xmlFree(ret);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment