本文整理汇总了C++中tinyxml2::XMLDocument类的典型用法代码示例。如果您正苦于以下问题:C++ XMLDocument类的具体用法?C++ XMLDocument怎么用?C++ XMLDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
}
示例2: throwIfError
/** Unfortunately, TinyXML2 does not provide good ways of reporting XML parsing
* errors. We could try to use GetErrorStr1() and GetErrorStr2(), but those
* just return pointers to parts of the document, and it is not OK to print
* parts of the document without carefully escaping special characters in it,
* which is probably not worthwhile. */
static void throwIfError(const tinyxml2::XMLDocument & doc)
{
if(!doc.Error()) { return; }
std::string msg("XML error.");
// doc.ErrorName is not available in Ubuntu's libtinyxml2-dev/trusty-backports package
// (2.1.0). But it would be nice to use it eventually once everyone has upgraded:
// std::string msg("XML error: ");
// msg += doc.ErrorName();
// msg += ".";
throw std::runtime_error(msg);
}
示例3: 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;
}
示例4: LoadFile
static tinyxml2::XMLError LoadFile(tinyxml2::XMLDocument &doc, const std::string &path)
{
FILE *f = fopen(path.c_str(),"rb");
if (!f)
return tinyxml2::XML_ERROR_FILE_NOT_FOUND;
// is file ok? if "path" is a folder then reading from it will cause ferror() to return a non-zero value
fgetc(f);
int errorcode = ferror(f);
fclose(f);
// if file is ok, try to load it
return (errorcode == 0) ? doc.LoadFile(path.c_str()) : tinyxml2::XML_ERROR_FILE_NOT_FOUND;
}
示例5: LoadXMLFromFile
// Загрузка данных в XML документ.
XMLError MainWindow::LoadXMLFromFile(QString& a_StrPath, tinyxml2::XMLDocument& a_xmlDoc)
{
DialogFileError we;
XMLError eErrOut;
//
eErrOut = XMLCheckResult(a_xmlDoc.LoadFile(a_StrPath.toStdString().c_str()));
if(eErrOut)
{
LOG(LOG_CAT_W, "File error: " << a_StrPath.toStdString());
we.exec();
}
else
{
LOG(LOG_CAT_I, "File loaded: " << a_StrPath.toStdString());
}
return eErrOut;
}
示例6: openXMLFile
static void openXMLFile(tinyxml2::XMLDocument & doc, const char* const filename)
{
int const result = doc.LoadFile(filename);
switch(result)
{
case tinyxml2::XML_SUCCESS:
break;
case tinyxml2::XML_ERROR_FILE_NOT_FOUND:
throw std::runtime_error("File not found");
case tinyxml2::XML_ERROR_FILE_COULD_NOT_BE_OPENED:
throw std::runtime_error("File not found");
default:
{
std::ostringstream oss;
oss << "Parse error = " << result;
throw std::runtime_error(oss.str());
}
};
}
示例7: addTextureStageState
void addTextureStageState(tinyxml2::XMLDocument& doc, tinyxml2::XMLElement* ele, u32 stage, D3DTEXTURESTAGESTATETYPE tp, u32 vl)
{
DWORD va = 0;
if (tp == D3DTSS_COLOROP)
{
if (stage == 0)
{
va = D3DTOP_MODULATE;
}
else
{
va = D3DTOP_DISABLE;
}
}
else if (tp == D3DTSS_ALPHAOP)
{
if (stage == 0)
{
va = D3DTOP_SELECTARG1;
}
else
{
va = D3DTOP_DISABLE;
}
}
else if(tp == D3DTSS_TEXCOORDINDEX)
{
va = stage;
}
else
{
va = Material::tTextureStageStateDefault_[tp];
}
if(va != vl)
{
tinyxml2::XMLElement* a = doc.NewElement("TextureStageState");
a->SetAttribute("stage", stage);
a->SetAttribute("type", tp);
a->SetAttribute("value", vl);
ele->LinkEndChild(a);
}
}
示例8: 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));
}
}
示例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: Serialization
void Sphere::Serialization( tinyxml2::XMLDocument& xmlDoc , tinyxml2::XMLElement* pRootElement )
{
{
pRootElement->SetAttribute( "type" , GetName() );
}
{
pRootElement->SetAttribute( "radius" , m_Radius );
}
{
char* pText = new char[50];
sprintf( pText , "%f,%f,%f" , mWorldPos.x , mWorldPos.y , mWorldPos.z );
tinyxml2::XMLElement* pTransformElement = xmlDoc.NewElement( "transform" );
pTransformElement->SetAttribute( "position" , pText );
pRootElement->InsertEndChild( pTransformElement );
SAFE_DELETE( pText );
}
}
示例11: openXMLFile
void openXMLFile(
tinyxml2::XMLDocument& doc, const char* const filename,
const common::ResourceRetrieverPtr& _retriever)
{
common::ResourceRetrieverPtr retriever;
if(_retriever)
retriever = _retriever;
else
retriever = std::make_shared<common::LocalResourceRetriever>();
const common::ResourcePtr resource = retriever->retrieve(filename);
if(!resource)
{
dtwarn << "[openXMLFile] Failed opening URI '"
<< filename << "'.\n";
throw std::runtime_error("Failed opening URI.");
}
// C++11 guarantees that std::string has contiguous storage.
const size_t size = resource->getSize();
std::string content;
content.resize(size);
if(resource->read(&content.front(), size, 1) != 1)
{
dtwarn << "[openXMLFile] Failed reading from URI '"
<< filename << "'.\n";
throw std::runtime_error("Failed reading from URI.");
}
int const result = doc.Parse(&content.front());
if(result != tinyxml2::XML_SUCCESS)
{
dtwarn << "[openXMLFile] Failed parsing XML: TinyXML2 returned error"
" code " << result << ".\n";
throw std::runtime_error("Failed parsing XML.");
}
}
示例12: 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
//.........这里部分代码省略.........
示例13: from_XML
void ProbabilisticLayer::from_XML(const tinyxml2::XMLDocument& document)
{
std::ostringstream buffer;
const tinyxml2::XMLElement* probabilistic_layer_element = document.FirstChildElement("ProbabilisticLayer");
if(!probabilistic_layer_element)
{
buffer << "OpenNN Exception: ProbabilisticLayer class.\n"
<< "void from_XML(const tinyxml2::XMLDocument&) method.\n"
<< "Probabilistic layer element is NULL.\n";
throw std::logic_error(buffer.str());
}
// Probabilistic neurons number
{
const tinyxml2::XMLElement* element = probabilistic_layer_element->FirstChildElement("ProbabilisticNeuronsNumber");
if(element)
{
const char* text = element->GetText();
if(text)
{
try
{
set_probabilistic_neurons_number(atoi(text));
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
// Probabilistic method
{
const tinyxml2::XMLElement* element = probabilistic_layer_element->FirstChildElement("ProbabilisticMethod");
if(element)
{
const char* text = element->GetText();
if(text)
{
try
{
std::string new_probabilistic_method(text);
set_probabilistic_method(new_probabilistic_method);
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
// Decision threshold
{
const tinyxml2::XMLElement* element = probabilistic_layer_element->FirstChildElement("DecisionThreshold");
if(element)
{
const char* text = element->GetText();
if(text)
{
try
{
set_decision_threshold(atof(text));
}
catch(const std::logic_error& e)
{
std::cout << e.what() << std::endl;
}
}
}
}
// Display
{
const tinyxml2::XMLElement* display_element = probabilistic_layer_element->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;
}
}
//.........这里部分代码省略.........
示例14: 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;
}
}
}
}
示例15: 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()) {
//.........这里部分代码省略.........