簡體   English   中英

用libxml2加載Collada

[英]Collada loading with libxml2

我想用libxml2加載collada。 我得到了COLLOADA節點,好的,然后嘗試獲得children標記-FAIL,children標記名稱是“ text”。 為什么? 如何獲得COLLADA節點的子節點?

xmlNode* geometries = xmlDocGetRootElement(doc)->children;

//at THIS point the geometries->name == "text"  WHY?
//IS not it supposed to be "asset"?

while(!xmlStrcmp(geometries->name, (const xmlChar*)"library_geometries")) 
geometries = geometries->next;


xmlNode* mesh = geometries->children;
for(uint i = 0; i < idx; i++)
mesh = mesh->next;

我哪里錯了?

好,問題解決了。 在每個->兒童和->下一個我都必須放置另一個->下一個(我不是遞歸地表示:)。 順便說一句,我不知道為什么,但是它能那樣工作。

在libxml2網站的以下示例中查看此方法:

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);
}

請注意,此代碼在打印節點名稱之前檢查節點是否為XML_ELEMENT_NODE類型。 您正在讀取的"text"節點是開始標記和結束標記之間的文本:

<myTag>This is the text between the tags</myTag>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM