void SetXMLValueForKey(const char* pKey, const char* value, rapidxml::xml_document<>& doc, rapidxml::xml_node<>* parentNode) { // check the params if (!pKey || !value || !parentNode) { return; } // find the node rapidxml::xml_node<>* node = parentNode->first_node(pKey); if (node) { if (node->first_node()) { node->first_node()->value(doc.allocate_string(value)); } else { node->value(doc.allocate_string(value)); } } else { parentNode->append_node(doc.allocate_node(rapidxml::node_element, doc.allocate_string(pKey), doc.allocate_string(value))); } }
void Genome::FillGenes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* chromosomeNode, Encoding& encoding){ for (rapidxml::xml_node<>* geneNode = chromosomeNode->first_node("Gene"); geneNode; geneNode = geneNode->next_sibling("Gene")) { char* pchRandomData = doc.allocate_string(encoding.RandomData(chromosomeNode).c_str()); geneNode->value(pchRandomData); } }
bool struct_xml(rapidxml::xml_node<> * & node, const ReqDeviceInfo & in, rapidxml::xml_document<> & doc) { node = doc.allocate_node(rapidxml::node_element, doc.allocate_string("ReqDeviceInfo")); /* @generate [ userId:int ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, "userId", doc.allocate_string(get_string(in.userId).c_str())); node->append_node(node1); } /* @generate [ userId:int ] end @ */ /* @generate [ deviceId:int ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, "deviceId", doc.allocate_string(get_string(in.deviceId).c_str())); node->append_node(node1); } /* @generate [ deviceId:int ] end @ */ return true; }
void XmlTree::appendRapidXmlNode( rapidxml::xml_document<char> &doc, rapidxml::xml_node<char> *parent ) const { rapidxml::node_type type; switch( getNodeType() ) { case XmlTree::NODE_ELEMENT: type = rapidxml::node_element; break; case XmlTree::NODE_COMMENT: type = rapidxml::node_comment; break; case XmlTree::NODE_CDATA: type = rapidxml::node_cdata; break; case XmlTree::NODE_DATA: type = rapidxml::node_data; break; default: throw ExcUnknownNodeType(); } rapidxml::xml_node<char> *node = 0; if( type == rapidxml::node_data ) { node = doc.allocate_node( type, NULL, doc.allocate_string( getValue().c_str() ) ); } else if( type == rapidxml::node_comment ) { node = doc.allocate_node( type, doc.allocate_string( getTag().c_str() ), doc.allocate_string( getValue().c_str() ) ); } else { node = doc.allocate_node( type, doc.allocate_string( getTag().c_str() ), NULL ); if( ! getValue().empty() ) node->append_node( doc.allocate_node( rapidxml::node_data, NULL, doc.allocate_string( getValue().c_str() ) ) ); } parent->append_node( node ); for( list<Attr>::const_iterator attrIt = mAttributes.begin(); attrIt != mAttributes.end(); ++attrIt ) node->append_attribute( doc.allocate_attribute( doc.allocate_string( attrIt->getName().c_str() ), doc.allocate_string( attrIt->getValue().c_str() ) ) ); for( Container::const_iterator childIt = mChildren.begin(); childIt != mChildren.end(); ++childIt ) (*childIt)->appendRapidXmlNode( doc, node ); }
void TacheUnitaire::xml_ajouterAttributs(rapidxml::xml_document<> & doc, rapidxml::xml_node<> & node_tache) { using namespace rapidxml; xml_attribute<> * attribute = doc.allocate_attribute("type", "u"); node_tache.append_attribute(attribute); if(getPreempte() == true) { attribute = doc.allocate_attribute("pre", "true"); node_tache.append_attribute(attribute); } char * node_name = doc.allocate_string( duree.toChar() ); attribute = doc.allocate_attribute( "duree", node_name ); node_tache.append_attribute(attribute); }
void Genome::GeneMutations(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* geneNode, Mutation& mutation, MutationChance mutationChance){ char* pchMutatedData; int nLow = 0; int nHigh = RAND_MAX; double dRandom; dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dBitString){ pchMutatedData = doc.allocate_string(mutation.BitString().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dFlipBits){ pchMutatedData = doc.allocate_string(mutation.FlipBits().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dBoundary){ pchMutatedData = doc.allocate_string(mutation.Boundary().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dUniform){ pchMutatedData = doc.allocate_string(mutation.Uniform().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dGaussian){ pchMutatedData = doc.allocate_string(mutation.Gaussian(mutationChance.dGaussianSigma).c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dDuplication){ pchMutatedData = doc.allocate_string(mutation.Duplication().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dDeletion){ pchMutatedData = doc.allocate_string(mutation.Deletion().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dInsertion){ pchMutatedData = doc.allocate_string(mutation.Insertion().c_str()); geneNode->value(pchMutatedData); } dRandom = (double)((rand() % (nHigh - nLow + 1)) + nLow)/nHigh; dRandom = dRandom * 100; if(dRandom <= mutationChance.dSwap){ pchMutatedData = doc.allocate_string(mutation.Swap().c_str()); geneNode->value(pchMutatedData); } }
void CTest::AddXMLAttributeValue( rapidxml::xml_document<>& pDoc, rapidxml::xml_node<>* pNode, const std::wstring& strwKey, const std::wstring& strwValue ) { std::string straValue = wstr2str(strwValue, CP_UTF8); std::string strakey = wstr2str(strwKey, CP_UTF8); pNode->append_attribute(pDoc.allocate_attribute(pDoc.allocate_string(strakey.c_str()), pDoc.allocate_string(straValue.c_str()) ) ); }
bool struct_xml(rapidxml::xml_node<> * & node, const RetDeviceInfo & in, rapidxml::xml_document<> & doc) { node = doc.allocate_node(rapidxml::node_element, doc.allocate_string("RetDeviceInfo")); /* @generate [ userId:int ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, "userId", doc.allocate_string(get_string(in.userId).c_str())); node->append_node(node1); } /* @generate [ userId:int ] end @ */ /* @generate [ deviceId:int ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, "deviceId", doc.allocate_string(get_string(in.deviceId).c_str())); node->append_node(node1); } /* @generate [ deviceId:int ] end @ */ /* @generate [ deviceInfos:std::vector< ReqDeviceInfo > ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("deviceInfos")); node->append_node(node1); auto node2 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("Vector")); node1->append_node(node2); for(auto i = in.deviceInfos.begin(); i != in.deviceInfos.end(); ++i) { rapidxml::xml_node<> * tmp = 0; if(!struct_xml(tmp, *i, doc)) return false; node2->append_node(tmp); } } /* @generate [ deviceInfos:std::vector< ReqDeviceInfo > ] end @ */ /* @generate [ deviceInfos2:std::vector< int > ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("deviceInfos2")); node->append_node(node1); auto node2 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("Vector")); node1->append_node(node2); for(auto i = in.deviceInfos2.begin(); i != in.deviceInfos2.end(); ++i) { rapidxml::xml_node<> * tmp = 0; if(!struct_xml(tmp, *i, doc)) return false; node2->append_node(tmp); } } /* @generate [ deviceInfos2:std::vector< int > ] end @ */ /* @generate [ deviceInfo:ReqDeviceInfo ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, "deviceInfo"); node->append_node(node1); rapidxml::xml_node<> * node2 = 0; if(!struct_xml(node2, in.deviceInfo, doc)) return false; node1->append_node(node2); } /* @generate [ deviceInfo:ReqDeviceInfo ] end @ */ /* @generate [ time:int ] begin @ */ { auto node1 = doc.allocate_node(rapidxml::node_element, "time", doc.allocate_string(get_string(in.time).c_str())); node->append_node(node1); } /* @generate [ time:int ] end @ */ return true; }
rapidxml::xml_node<char>* parsed_config() { ctext = doc.allocate_string(xml_config.c_str()); doc.parse< rapidxml::parse_no_data_nodes >(ctext); return doc.first_node(); }