2016-12-22 9 views

答えて

0

これXmlSoftは、最も一般的なタスクを実行する方法を示すlibxml2のための例の偉大なセットを持っています。

xmlDoc *doc = NULL; 
xmlNode *root_element = NULL; 

if (argc != 2) 
    return(1); 

/* 
* this initialize the library and check potential ABI mismatches 
* between the version it was compiled for and the actual shared 
* library used. 
*/ 
LIBXML_TEST_VERSION 

/*parse the file and get the DOM */ 
doc = xmlReadFile(argv[1], NULL, 0); 

if (doc == NULL) { 
    printf("error: could not parse file %s\n", argv[1]); 
} 

/*Get the root element node */ 
root_element = xmlDocGetRootElement(doc); 

print_element_names(root_element); 

/*free the document */ 
xmlFreeDoc(doc); 

/* 
*Free the global variables that may 
*have been allocated by the parser. 
*/ 
xmlCleanupParser(); 


static void 
print_element_names(xmlNode * a_node) 
{ 
    xmlNode *cur_node = NULL; 

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) { 
     if (cur_node->type == XML_ELEMENT_NODE) { 
      printf("node type: Element, name: %s\n", cur_node->name); 
     } 

     print_element_names(cur_node->children); 
    } 
} 
+0

ありがとうございます。 – user3214224

関連する問題