libxml2에서 attribute 값 가져오는 방법
글쓴이: bosub / 작성시간: 수, 2006/02/15 - 7:17오후
limxml2 라이브러리를 이용해서 어트리뷰트 값을 가져오는 방법이 무엇인가요?
아래와 같은 xml 문서가 있습니다. 이 문서에서 node 의 type 인 1을 가져오고 싶습니다.
<message> <node type="1"> <to> home </to> <from> house </from> </node> </message>
위 문서를 아래 소스를 응용해서 어트리뷰터 값을 가져 올 수 있을까요?
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);
}
}
int
main(int argc, char **argv)
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
if (argc != 2)
return(1);
doc = xmlReadFile(argv[1], NULL, 0);
if (doc == NULL) {
printf("error: could not parse file %s\n", argv[1]);
}
root_element = xmlDocGetRootElement(doc);
print_element_names(root_element);
xmlFreeDoc(doc);
xmlCleanupParser();
return 0;
}
답변 좀 꼭 부탁드립니다.
Forums:


Re: libxml2에서 attribute 값 가져오는 방법
xmlGetProp()함수가 있었네요. 이거 사용하면 되네요 *^^*
5초 앞이라도 내다 볼 수 있다면..
댓글 달기