포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 20MB 입니다.

출처: http://kldp.org/node/64566
==============

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: %sn", 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 %sn", argv[1]);
    }

    root_element = xmlDocGetRootElement(doc);

    print_element_names(root_element);

    xmlFreeDoc(doc);

    xmlCleanupParser();

    return 0;
}

답변 좀 꼭 부탁드립니다.

xmlGetProp()함수가 있었네요. 이거 사용하면 되네요 *^^*

List of Articles
번호 제목 글쓴이 날짜 조회 수sort
53 find 명령어 활용법 고현철 2009-01-30 6272
52 vi 사용법 - block 지정 고현철 2009-01-30 6303
51 유용한 ARM 어셈블리 (if, for, do_while, switch) 김재훈 2009-01-31 6333
50 우분투 리눅스 8.10 네트워크 수동 설정 방법 [2] 김재훈 2009-03-23 6367
49 Embedded Linux Debugging HowTo file 김재훈 2009-04-27 6396
48 iconv euckr_to_utf8 고현철 2009-01-30 6418
47 SDL tslib initialize 고현철 2009-04-09 6426
46 wxWidget hello unix example file 고도리 2008-07-18 6494
45 wxWidget odbc file 고도리 2008-07-18 6565
44 windows/linux에서 작업했던 tutorial입니다. file 고도리 2008-07-18 6626
43 펌웨어 프로그래밍 팁 - atoi() 함수 구현 김재훈 2009-01-31 6806
42 devcpp howto입니다.(devcpp/wxWidget/SDL) file 고도리 2008-07-18 6915
41 wxWidget sample program 올리기 - windows/linux file 고도리 2008-07-18 6935
40 Teach Yourself Shell Programming in 24 Hours file 김재훈 2009-05-17 7081
39 The GNU C Library Reference Manual (한글판) file [3] 김재훈 2009-04-19 7186
38 Linux C++ Programming HowTo file 김재훈 2009-04-26 7193
37 Linux application에서의 clock과 system timer설정 고도리 2011-08-15 7383
36 ARM Developer Suiite (ADS) 메뉴얼 모음 file 김재훈 2009-03-31 7397
35 GStreamer On TI DaVinci and OMAP Platform 강좌 .... 장석원 2009-04-27 7416
34 wxDevcpp를 이용한 windows용 tutorial입니다. file 고도리 2008-07-18 7421

사용자 로그인