2013-11-20 5 views
0

valuechild atribute으로받는 방법은 무엇입니까? 예 : xml :libxml 자녀 atribute를 얻는 방법

<root> 
    <child> 
     <info>Lala</info> 
    </child> 
</root> 

나는 어떻게 Lala을 얻습니까? 나는 이것을 시도 (하지만 :(작동 나던) 내가하지 LaLa 얻을이 코드를 시작하면

void parsePackage (xmlDocPtr doc, xmlNodePtr cur) { 
     xmlChar *key; 
     xmlChar *uri; 
     cur = cur->xmlChildrenNode; 
     while (cur != NULL) { 
     if ((!xmlStrcmp(cur->name, (const xmlChar *)"child"))) { 
      key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 
      uri = xmlGetProp(cur, (const xmlChar *)"info"); 
      printf("Info: %s\n", uri); 
      xmlFree(key); 
     } 
      cur = cur->next; 
     } 
    return; 
} 

void parseDoc() { 
    xmlDocPtr doc; 
    xmlNodePtr cur; 

    doc = xmlParseFile("test.xml"); 

    if (doc == NULL) { 
     fprintf(stderr,"Document not parsed successfully. \n"); 
     return; 
    } 

    cur = xmlDocGetRootElement(doc); 

    if (cur == NULL) { 
     fprintf(stderr,"empty document\n"); 
     xmlFreeDoc(doc); 
     return; 
    } 

    if (xmlStrcmp(cur->name, (const xmlChar *) "root")) { 
     fprintf(stderr,"document of the wrong type, root node != package"); 
     xmlFreeDoc(doc); 
     return; 
    } 

    parsePackage(doc, cur); 
    xmlFreeDoc(doc); 
    return; 
} 

), 나는 null를 얻을.
편집자 (귀하의 게시물이 주로 코드 인 것 같습니다. 자세한 내용을 추가하십시오.)이 케이스에 대한 자세한 내용은 없습니다.

답변

1

(const xmlChar *)"cild") 당신은 사용해야하지만, "정보"는 "아이"노드의 자식이 아닌 속성이다. "info"노드에서 xmlNodeGetContent()를 사용해야합니다.

0

오 프린트 것 같습니다. 당신은 현재 노드의 속성 값을 검색 xmlGetProp()를 사용하는 (const xmlChar *)"child") 대신

+0

예 잘못된 인쇄물 D – ternes3