void XMLNode::init(xmlNode * theNode) { xmlAttr *attribute = theNode->properties; nodeName = (const char*)(theNode->name); while (attribute) { xmlNode* attrNode = attribute->children; attributes[std::string((const char*)attribute->name)] = std::string((const char*)attrNode->content); AC_TRACE << " attr " << std::string((const char*)attribute->name) << " = " << std::string((const char*)attrNode->content); attribute = attribute->next; } if (attributes.find("name") != attributes.end()) { name = attributes["name"]; } xmlNode* currentChild = theNode->children; for (; currentChild; currentChild = currentChild->next) { if (currentChild->type == XML_ELEMENT_NODE) { XMLNodePtr childXMLNode = XMLNodePtr(new XMLNode(currentChild)); AC_TRACE << "add child for " << nodeName << ": " << childXMLNode->nodeName; children.push_back(childXMLNode); } else if (currentChild->type == XML_TEXT_NODE) { if (content.size() == 0) { //this is needed to avoid resetting content from CDATA by following TEXT content = std::string((const char*)currentChild->content); AC_TRACE << "set content for TEXT " << content; } } else if (currentChild->type == XML_CDATA_SECTION_NODE) { //cdata-sections content = std::string((const char*)currentChild->content); AC_TRACE << "set content for CDATA " << content; } } }
XMLNodePtr XMLNode::LastNode( std::string const & name ){ rapidxml::xml_node<>* node = static_cast< rapidxml::xml_node<>* >(node_)->last_node( name.c_str() ); if( node ){ return MakeSharedPtr<XMLNode>(node); } else{ return XMLNodePtr(); } }
XMLNodePtr XMLNode::LastNode(){ rapidxml::xml_node<>* node = static_cast< rapidxml::xml_node<>* >(node_)->last_node(); if( node ){ return MakeSharedPtr<XMLNode>(node); } else{ return XMLNodePtr(); } }
/*! \exception throws xmlpp::xmlerror if requested children was not found */ XMLNodePtr XMLNode::firstchild(const string &n) { XMLNodeListConstIterator it; // search for child for(it=nodelist.begin(); it!=nodelist.end(); it++) { if ((*it)->name() == n) return *it; } // no valid child found throw xmlerror(xml_name_not_found, n); return XMLNodePtr(NULL); }
XMLNodePtr XMLNode::NextSibling() { rapidxml::xml_node<>* node = static_cast<rapidxml::xml_node<>*>(node_)->next_sibling(); if (node) { return MakeSharedPtr<XMLNode>(node); } else { return XMLNodePtr(); } }
XMLNodePtr XMLNode::NextSibling(std::string const & name) { rapidxml::xml_node<>* node = static_cast<rapidxml::xml_node<>*>(node_)->next_sibling(name.c_str()); if (node) { return MakeSharedPtr<XMLNode>(node); } else { return XMLNodePtr(); } }