本文整理汇总了C++中tinyxml2::XMLDocument::FirstChildElement方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLDocument::FirstChildElement方法的具体用法?C++ XMLDocument::FirstChildElement怎么用?C++ XMLDocument::FirstChildElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinyxml2::XMLDocument
的用法示例。
在下文中一共展示了XMLDocument::FirstChildElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_Tag_Txt__From_Xml_Doc
// прочитать Тег c Загруженного файла XML
// "локация тега" - вектор "вглубь" структуры
string rd_Xml_tags_Txt_reader::get_Tag_Txt__From_Xml_Doc(
tinyxml2::XMLDocument& doc, const vector<const char*>& location, const char* tag)
{
string txt;
unsigned loc_Sze = location.size();
tinyxml2::XMLElement* ptEl_location;
tinyxml2::XMLElement* ptEl;
if(loc_Sze)
{
ptEl_location = doc.FirstChildElement(location[0]);
for(unsigned n = 1; n < loc_Sze; n++)
{
ptEl_location = ptEl_location->FirstChildElement(location[n]);
}
ptEl = ptEl_location->FirstChildElement(tag);
}
else
ptEl = doc.FirstChildElement(tag);
const char* t = ptEl->GetText();
if(t) txt = t;
return txt;
}
示例2: readDocument
/*
* \brief This function is called from the constructors to check verion of the read document
* and to read the game state of this storage
*/
void readDocument() {
if (!m_XMLDoc.FirstChildElement("snapshot")) {
throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
"XMLdoc has no snapshot node",
__FILE__);
}
tinyxml2::XMLElement *pElem = m_XMLDoc.FirstChildElement("snapshot");
m_eCurrentGameState
= XMLHelper::EnumAttribute<CGameState::EGameStates>(
pElem,
"game_state",
CGameState::GS_MAIN_MENU);
if (m_eCurrentGameState >= CGameState::EGameStates::GS_COUNT) {
throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
"Game state " + Ogre::StringConverter::toString(m_eCurrentGameState) + " is not valid!", __FILE__);
}
m_iVersion = XMLHelper::IntAttribute(pElem, "version", -1);
if (m_iVersion != SNAPSHOT_VERSION) {
throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
"Snapshot version " + Ogre::StringConverter::toString(m_iVersion)
+ " does not match with the required verion of "
+ Ogre::StringConverter::toString(SNAPSHOT_VERSION),
__FILE__);
}
}
示例3: from_XML
void TestingAnalysis::from_XML(const tinyxml2::XMLDocument& document)
{
std::ostringstream buffer;
const tinyxml2::XMLElement* root_element = document.FirstChildElement("TestingAnalysis");
if(!root_element)
{
buffer << "OpenNN Exception: TestingAnalysis class.\n"
<< "void from_XML(const tinyxml2::XMLDocument&) method.\n"
<< "Testing analysis element is NULL.\n";
throw std::logic_error(buffer.str());
}
// Display
const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");
if(element)
{
std::string new_display_string = element->GetText();
try
{
set_display(new_display_string != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
示例4: from_XML
void NormalizedSquaredError::from_XML(const tinyxml2::XMLDocument& document)
{
const tinyxml2::XMLElement* root_element = document.FirstChildElement("NormalizedSquaredError");
if(!root_element)
{
return;
}
const tinyxml2::XMLElement* display_element = root_element->FirstChildElement("Display");
if(display_element)
{
const std::string new_display_string = display_element->GetText();
try
{
set_display(new_display_string != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
示例5: from_XML
void IndependentParametersError::from_XML(const tinyxml2::XMLDocument& document)
{
const tinyxml2::XMLElement* root_element = document.FirstChildElement("IndependentParametersError");
if(!root_element)
{
std::ostringstream buffer;
buffer << "OpenNN Exception: IndependentParametersError class.\n"
<< "void from_XML(const tinyxml2::XMLDocument&) method.\n"
<< "Independent parameters error element is NULL.\n";
throw std::logic_error(buffer.str());
}
// Display
{
const tinyxml2::XMLElement* display_element = root_element->FirstChildElement("Display");
if(display_element)
{
const std::string new_display_string = display_element->GetText();
try
{
set_display(new_display_string != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
示例6: from_XML
void NumericalIntegration::from_XML(const tinyxml2::XMLDocument& document)
{
const tinyxml2::XMLElement* root_element = document.FirstChildElement("NumericalIntegration");
if(!root_element)
{
std::ostringstream buffer;
buffer << "OpenNN Exception: NumericalIntegration class.\n"
<< "void from_XML(const tinyxml2::XMLDocument&) method.\n"
<< "Numerical integration element is NULL.\n";
throw std::logic_error(buffer.str());
}
// Numerical integration method
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("NumericalIntegrationMethod");
if(element)
{
const std::string new_numerical_integration_method = element->GetText();
try
{
set_numerical_integration_method(new_numerical_integration_method);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
// Display
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");
if(element)
{
const std::string new_display = element->GetText();
try
{
set_display(new_display != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
示例7: from_XML
void NeuralParametersNorm::from_XML(const tinyxml2::XMLDocument& document)
{
const tinyxml2::XMLElement* root_element = document.FirstChildElement("NeuralParametersNorm");
if(!root_element)
{
std::ostringstream buffer;
buffer << "OpenNN Exception: NeuralParametersNorm class.\n"
<< "void from_XML(const tinyxml2::XMLDocument&) method.\n"
<< "Neural parameters norm element is NULL.\n";
throw std::logic_error(buffer.str());
}
// Neural parameters norm weight
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("NeuralParametersNormWeight");
if(element)
{
try
{
const double new_neural_parameters_norm_weight = atof(element->GetText());
set_neural_parameters_norm_weight(new_neural_parameters_norm_weight);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
// Display
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");
if(element)
{
try
{
const std::string new_display_string = element->GetText();
set_display(new_display_string != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
示例8: string
// прочитать группу Тегов c Загруженного файла XML
// "локация тегов" - вектор "вглубь" структуры
vector<string> rd_Xml_tags_Txt_reader::get_Tags_Txt__From_Xml_Doc(
tinyxml2::XMLDocument& doc, const vector<const char*>& location, const char* tag)
{
vector<string> vTxt;
unsigned loc_Sze = location.size();
tinyxml2::XMLElement* ptEl_location;
tinyxml2::XMLElement* ptEl;
tinyxml2::XMLElement* ptEl_last;
if(loc_Sze)
{
ptEl_location = doc.FirstChildElement(location[0]);
for(unsigned n = 1; n < loc_Sze; n++)
{
ptEl_location = ptEl_location->FirstChildElement(location[n]);
}
ptEl = ptEl_location->FirstChildElement(tag);
ptEl_last = ptEl_location->LastChildElement(tag);
}
else
{
ptEl = doc.FirstChildElement(tag);
ptEl_last = doc.LastChildElement(tag);
}
const char* data;
for(; ptEl; ptEl = ptEl->NextSiblingElement())
{
data = ptEl->GetText();
if(data) vTxt.push_back( data );
else vTxt.push_back( string() );
if(ptEl == ptEl_last) break;
}
vTxt.shrink_to_fit();
return vTxt;
}
示例9: from_XML
void RegularizationTerm::from_XML(const tinyxml2::XMLDocument& document)
{
// Display warnings
const tinyxml2::XMLElement* display_element = document.FirstChildElement("Display");
if(display_element)
{
std::string new_display_string = display_element->GetText();
try
{
set_display(new_display_string != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
示例10: load
void TileMap::load(tinyxml2::XMLDocument & doc)
{
std::string data;
tinyxml2::XMLElement * element = doc.FirstChildElement("map");
element->FirstChildElement("width")->QueryIntText(&m_width);
element->FirstChildElement("height")->QueryIntText(&m_height);
element->FirstChildElement("tile_size")->QueryIntText(&m_tileSize);
data = element->FirstChildElement("data")->GetText();
std::cout << "width: " << m_width << " height: " << m_height << "\n";
std::istringstream ss(data);
std::string token;
while (std::getline(ss, token, ','))
{
if (m_tiles.size() == 0 || m_tiles.back().size() >= static_cast<unsigned>(m_width))
m_tiles.emplace_back();
m_tiles.back().push_back(std::stoi(token));
}
}
示例11: from_XML
void BoundingLayer::from_XML(const tinyxml2::XMLDocument& document)
{
// Control sentence
// {
// const char* text = bounding_layer_element->GetText();
// const std::string string(text);
// if(string != "BoundingLayer")
// {
// std::ostringstream buffer;
// buffer << "OpenNN Exception: BoundingLayer class.\n"
// << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
// << "Unkown root element: " << text << ".\n";
// throw std::logic_error(buffer.str());
// }
// }
// Lower bounds
{
const tinyxml2::XMLElement* lower_bounds_element = document.FirstChildElement("LowerBounds");
if(lower_bounds_element)
{
const char* lower_bounds_text = lower_bounds_element->GetText();
if(lower_bounds_text)
{
Vector<double> new_lower_bounds;
new_lower_bounds.parse(lower_bounds_text);
try
{
set_lower_bounds(new_lower_bounds);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
// Upper bounds
{
const tinyxml2::XMLElement* upper_bounds_element = document.FirstChildElement("UpperBounds");
if(upper_bounds_element)
{
const char* upper_bounds_text = upper_bounds_element->GetText();
if(upper_bounds_text)
{
Vector<double> new_upper_bounds;
new_upper_bounds.parse(upper_bounds_text);
try
{
set_upper_bounds(new_upper_bounds);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
// Display
{
const tinyxml2::XMLElement* display_element = document.FirstChildElement("Display");
if(display_element)
{
std::string new_display_string = display_element->GetText();
try
{
set_display(new_display_string != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
示例12: load
bool Library::load(const tinyxml2::XMLDocument &doc)
{
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
if (rootnode == NULL)
return false;
if (strcmp(rootnode->Name(),"def") != 0)
return false;
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(),"memory")==0 || strcmp(node->Name(),"resource")==0) {
if (strcmp(node->Name(), "memory")==0)
while (!ismemory(++allocid));
else
while (!isresource(++allocid));
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
if (strcmp(memorynode->Name(),"alloc")==0) {
_alloc[memorynode->GetText()] = allocid;
const char *init = memorynode->Attribute("init");
if (init && strcmp(init,"false")==0) {
returnuninitdata.insert(memorynode->GetText());
}
} else if (strcmp(memorynode->Name(),"dealloc")==0)
_dealloc[memorynode->GetText()] = allocid;
else if (strcmp(memorynode->Name(),"use")==0)
use.insert(memorynode->GetText());
else
return false;
}
}
else if (strcmp(node->Name(),"function")==0) {
const char *name = node->Attribute("name");
if (name == NULL)
return false;
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(),"noreturn")==0)
_noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
else if (strcmp(functionnode->Name(),"leak-ignore")==0)
leakignore.insert(name);
else if (strcmp(functionnode->Name(), "arg") == 0 && functionnode->Attribute("nr") != NULL) {
const int nr = atoi(functionnode->Attribute("nr"));
bool notbool = false;
bool notnull = false;
bool notuninit = false;
bool formatstr = false;
bool strz = false;
std::string valid;
for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
if (strcmp(argnode->Name(), "not-bool") == 0)
notbool = true;
else if (strcmp(argnode->Name(), "not-null") == 0)
notnull = true;
else if (strcmp(argnode->Name(), "not-uninit") == 0)
notuninit = true;
else if (strcmp(argnode->Name(), "formatstr") == 0)
formatstr = true;
else if (strcmp(argnode->Name(), "strz") == 0)
strz = true;
else if (strcmp(argnode->Name(), "valid") == 0) {
// Validate the validation expression
const char *p = argnode->GetText();
if (!std::isdigit(*p))
return false;
for (; *p; p++) {
if (std::isdigit(*p))
continue;
if (*p == '-' && std::isdigit(*(p-1)))
continue;
if (*p == ',' && *(p+1) != ',')
continue;
return false;
}
// Set validation expression
valid = argnode->GetText();
}
else
return false;
}
argumentChecks[name][nr].notbool = notbool;
argumentChecks[name][nr].notnull = notnull;
argumentChecks[name][nr].notuninit = notuninit;
argumentChecks[name][nr].formatstr = formatstr;
argumentChecks[name][nr].strz = strz;
argumentChecks[name][nr].valid = valid;
} else if (strcmp(functionnode->Name(), "ignorefunction") == 0) {
_ignorefunction.insert(name);
} else
return false;
}
}
else if (strcmp(node->Name(), "markup") == 0) {
const char * const extension = node->Attribute("ext");
if (!extension)
return false;
//.........这里部分代码省略.........
示例13: from_XML
void PlugIn::from_XML(const tinyxml2::XMLDocument& document) {
// Independent variables number
{
const tinyxml2::XMLElement* element =
document.FirstChildElement("IndependentVariablesNumber");
if (element) {
const char* text = element->GetText();
if (text) {
try {
set_independent_variables_number(atoi(text));
}
catch (const std::logic_error & e) {
std::cout << e.what() << std::endl;
}
}
}
}
// Dependent variables number
{
const tinyxml2::XMLElement* element =
document.FirstChildElement("DependentVariablesNumber");
if (element) {
const char* text = element->GetText();
if (text) {
try {
set_dependent_variables_number(atoi(text));
}
catch (const std::logic_error & e) {
std::cout << e.what() << std::endl;
}
}
}
}
// Input method
{
const tinyxml2::XMLElement* input_method_element =
document.FirstChildElement("InputMethod");
if (input_method_element) {
const char* input_method_text = input_method_element->GetText();
if (input_method_text) {
try {
set_input_method(input_method_text);
}
catch (const std::logic_error & e) {
std::cout << e.what() << std::endl;
}
}
}
}
// Template file_name
{
const tinyxml2::XMLElement* template_file_name_element =
document.FirstChildElement("TemplateFileName");
if (template_file_name_element) {
const char* template_file_name_text =
template_file_name_element->GetText();
if (template_file_name_text) {
try {
set_template_file_name(template_file_name_text);
}
catch (const std::logic_error & e) {
std::cout << e.what() << std::endl;
}
}
}
}
// Input file_name
{
const tinyxml2::XMLElement* input_file_name_element =
document.FirstChildElement("InputFileName");
if (input_file_name_element) {
const char* input_file_name_text = input_file_name_element->GetText();
if (input_file_name_text) {
try {
set_input_file_name(input_file_name_text);
}
catch (const std::logic_error & e) {
std::cout << e.what() << std::endl;
}
}
}
}
// Batch file_name
{
const tinyxml2::XMLElement* script_file_name_element =
//.........这里部分代码省略.........
示例14: load
bool Library::load(const tinyxml2::XMLDocument &doc)
{
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
if (rootnode == NULL)
return false;
if (strcmp(rootnode->Name(),"def") != 0)
return false;
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(),"memory")==0 || strcmp(node->Name(),"resource")==0) {
if (strcmp(node->Name(), "memory")==0)
while (!ismemory(++allocid));
else
while (!isresource(++allocid));
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
if (strcmp(memorynode->Name(),"alloc")==0) {
_alloc[memorynode->GetText()] = allocid;
const char *init = memorynode->Attribute("init");
if (init && strcmp(init,"false")==0) {
returnuninitdata.insert(memorynode->GetText());
}
} else if (strcmp(memorynode->Name(),"dealloc")==0)
_dealloc[memorynode->GetText()] = allocid;
else if (strcmp(memorynode->Name(),"use")==0)
use.insert(memorynode->GetText());
else
return false;
}
}
else if (strcmp(node->Name(),"function")==0) {
const char *name = node->Attribute("name");
if (name == NULL)
return false;
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(),"noreturn")==0)
_noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
else if (strcmp(functionnode->Name(),"leak-ignore")==0)
leakignore.insert(name);
else if (strcmp(functionnode->Name(), "arg") == 0 && functionnode->Attribute("nr") != NULL) {
const int nr = atoi(functionnode->Attribute("nr"));
bool notnull = false;
bool notuninit = false;
bool formatstr = false;
bool strz = false;
for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
if (strcmp(argnode->Name(), "not-null") == 0)
notnull = true;
else if (strcmp(argnode->Name(), "not-uninit") == 0)
notuninit = true;
else if (strcmp(argnode->Name(), "formatstr") == 0)
formatstr = true;
else if (strcmp(argnode->Name(), "strz") == 0)
strz = true;
else
return false;
}
argumentChecks[name][nr].notnull = notnull;
argumentChecks[name][nr].notuninit = notuninit;
argumentChecks[name][nr].formatstr = formatstr;
argumentChecks[name][nr].strz = strz;
} else if (strcmp(functionnode->Name(), "ignorefunction") == 0) {
_ignorefunction[name] = (strcmp(functionnode->GetText(), "true") == 0);
} else
return false;
}
}
else if (strcmp(node->Name(),"files")==0) {
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "file") == 0) {
_markupExtensions.insert(functionnode->Attribute("ext"));
const char * report = functionnode->Attribute("reporterrors");
if (report)
_reporterrors[functionnode->Attribute("ext")] = strcmp(report, "true")==0;
} else
return false;
}
}
else if (strcmp(node->Name(), "keywords") == 0) {
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "library") == 0) {
const char * const extension = functionnode->Attribute("extension");
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
if (strcmp(librarynode->Name(), "keyword") == 0) {
_keywords[extension].push_back(librarynode->Attribute("name"));
} else
return false;
}
} else
return false;
}
}
else if (strcmp(node->Name(), "exported") == 0) {
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
//.........这里部分代码省略.........
示例15: from_XML
void KappaCoefficientOptimizationThreshold::from_XML(const tinyxml2::XMLDocument& document)
{
const tinyxml2::XMLElement* root_element = document.FirstChildElement("KappaCoefficientOptimizationThreshold");
if(!root_element)
{
std::ostringstream buffer;
buffer << "OpenNN Exception: KappaCoefficientOptimizationThreshold class.\n"
<< "void from_XML(const tinyxml2::XMLDocument&) method.\n"
<< "KappaCoefficientOptimizationThreshold element is NULL.\n";
throw std::logic_error(buffer.str());
}
// Minimum threshold
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("MinimumThreshold");
if(element)
{
const double new_minimum_threshold = atof(element->GetText());
try
{
set_minimum_threshold(new_minimum_threshold);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
// Maximum threshold
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumThreshold");
if(element)
{
const double new_maximum_threshold = atof(element->GetText());
try
{
set_maximum_threshold(new_maximum_threshold);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
// Step
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("Step");
if(element)
{
const double new_step = atof(element->GetText());
try
{
set_step(new_step);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
// Reserve function data
{
const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveFunctionData");
if(element)
{
const std::string new_reserve_function_data = element->GetText();
try
{
set_reserve_function_data(new_reserve_function_data != "0");
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
// Display
// {
// const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");
// if(element)
// {
// const std::string new_display = element->GetText();
// try
//.........这里部分代码省略.........