【问题标题】:Collada loading with libxml2Collada 使用 libxml2 加载
【发布时间】:2011-03-27 02:11:34
【问题描述】:

我想用 libxml2 加载 collada。 我得到 COLLOADA 节点,好的,然后我尝试获取子标签 - 失败,子标签名称是“文本”。 为什么?如何获取 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;

我哪里错了?

【问题讨论】:

    标签: c++ libxml2 collada


    【解决方案1】:

    好的,问题解决了。 在每个 ->children 和 ->next 中,我都必须放置另一个 ->next(我不是递归的意思:))。 顺便说一句,我不知道为什么,但它是这样工作的。

    【讨论】:

      【解决方案2】:

      从libxml2网站的this example看这个方法:

      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>
      

      【讨论】:

        猜你喜欢
        • 2012-11-01
        • 2013-03-09
        • 2012-02-19
        • 2016-03-26
        • 2015-11-06
        • 2017-07-15
        • 2015-08-31
        • 2019-02-08
        • 2015-08-03
        相关资源
        最近更新 更多