/** * This source file is part of OgreColladaPlugin * an addon for OGRE (Object-oriented Graphics Rendering Engine) * For the latest info, see http://www.ogre3d.org/ * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA, or go to * http://www.gnu.org/copyleft/lesser.txt. * * @author Philipp Hartl * @see README */ #include "OgreColladaUtils.h" #include "OgreColladaSyntax.h" #include "OgreColourValue.h" #include "OgreStringVector.h" namespace Ogre { //------------------------------------------------------------------------- xmlNode *ColladaUtils::getChildById(xmlNode *start, const char *id) { if (start != NULL && id != NULL) { // we are looking for strings without '#' if (*id == '#') ++id; // walk through all children for (xmlNode *c = start->children; c != NULL; c = c->next) { // we are interested on element nodes only if (c->type != XML_ELEMENT_NODE) continue; String cid = getProperty(c, CS_ATR_ID); if (!cid.empty()) { if (cid == id) return c; } } } return NULL; } //------------------------------------------------------------------------- xmlNode *ColladaUtils::getChildByTagName(xmlNode *start, const String &tagname) { if (start != NULL && !tagname.empty()) { for (xmlNode *c = start->children; c != NULL; c = c->next) { if (c->type != XML_ELEMENT_NODE) continue; if (tagname == (const char *)c->name) return c; } } return NULL; } //------------------------------------------------------------------------- xmlNodePtrVector ColladaUtils::getChildsByTagName(xmlNode *start, const String &tagname) { xmlNodePtrVector nodes; if (start != NULL && !tagname.empty()) { for (xmlNode *c = start->children; c != NULL; c = c->next) { if (c->type != XML_ELEMENT_NODE) continue; if (tagname == (const char *)c->name) nodes.push_back(c); } } return nodes; } //------------------------------------------------------------------------- String ColladaUtils::getContent(xmlNode *node) { String result = ""; if (node != NULL) { xmlChar *data = xmlNodeGetContent(node); if (data != NULL) { result = (const char *)data; xmlFree(data); } } return result; } //------------------------------------------------------------------------- String ColladaUtils::getContentDirect(xmlNode *node) { String result = ""; if (node != NULL) { if (node->children != NULL && node->children->type == XML_TEXT_NODE && node->children->content != NULL) { result = (const char *)node->children->content; } } return result; } //------------------------------------------------------------------------- String ColladaUtils::getProperty(xmlNode *node, const char *property) { String result = ""; if (node != NULL && property != NULL) { xmlChar *data = xmlGetProp(node, (const xmlChar *)property); if (data != NULL) { result = (const char *)data; xmlFree(data); } } return result; } //------------------------------------------------------------------------- String ColladaUtils::getProperty(xmlNode *node, const String &property) { String result = ""; if (node != NULL && !property.empty()) { xmlChar *data = xmlGetProp(node, (const xmlChar *)property.c_str()); if (data != NULL) { result = (const char *)data; xmlFree(data); } } return result; } //------------------------------------------------------------------------- void ColladaUtils::printChildElements(xmlNode *node) { for (xmlNode *child = node->children; child != NULL; child = child->next) { if (child->type != XML_ELEMENT_NODE) continue; LogManager::getSingleton().logMessage("ColladaUtils::printElementNames - xml element: " + String((const char *)child->name)); } } //------------------------------------------------------------------------- void ColladaUtils::printAllElements(xmlNode *node) { for (xmlNode *cur_node = node; cur_node != NULL; cur_node = cur_node->next) { if (cur_node->type != XML_ELEMENT_NODE) continue; LogManager::getSingleton().logMessage("ColladaUtils::printElementNames - xml element: " + String((const char *)cur_node->name)); printAllElements(cur_node->children); } } }