本文整理汇总了C++中XMLDocument::RootElement方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLDocument::RootElement方法的具体用法?C++ XMLDocument::RootElement怎么用?C++ XMLDocument::RootElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLDocument
的用法示例。
在下文中一共展示了XMLDocument::RootElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readVisualSceneInstanceGeometries
void readVisualSceneInstanceGeometries(XMLDocument& doc, btHashMap<btHashString,int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances)
{
btHashMap<btHashString,XMLElement* > allVisualScenes;
XMLElement* libVisualScenes = doc.RootElement()->FirstChildElement("library_visual_scenes");
if (libVisualScenes==0)
return;
{
for(XMLElement* scene = libVisualScenes->FirstChildElement("visual_scene");
scene != NULL; scene = scene->NextSiblingElement("visual_scene"))
{
const char* sceneName = scene->Attribute("id");
allVisualScenes.insert(sceneName,scene);
}
}
XMLElement* scene = 0;
{
XMLElement* scenes = doc.RootElement()->FirstChildElement("scene");
if (scenes)
{
XMLElement* instanceSceneReference = scenes->FirstChildElement("instance_visual_scene");
if (instanceSceneReference)
{
const char* instanceSceneUrl = instanceSceneReference->Attribute("url");
XMLElement** sceneInstancePtr = allVisualScenes[instanceSceneUrl+1];//skip #
if (sceneInstancePtr)
{
scene = *sceneInstancePtr;
}
}
}
}
if (scene)
{
for(XMLElement* node = scene->FirstChildElement("node");
node != NULL; node = node->NextSiblingElement("node"))
{
btMatrix4x4 identity;
identity.setIdentity();
btVector3 identScaling(1,1,1);
readNodeHierarchy(node,name2Shape,visualShapeInstances, identity);
}
}
}
示例2: Read
REBOOL REXMLSerializableReader::Read(const REString & xmlString)
{
#ifndef __RE_NO_XML_PARSER_PRIVATE__
_totalElementsCount = 0;
_processedElementsCount = 0;
_isError = false;
if (_controller && _callBack.CreateNewObject)
{
XMLDocument doc;
doc.Parse(xmlString.UTF8String());
if (doc.Error()) { return false; }
XMLElement * root = doc.RootElement();
if (root == NULL) { return false; }
const char * rootVal = root->Value();
if (rootVal)
{
if (strcmp(rootVal, "viewcontroller") == 0)
{
_totalElementsCount = this->CalculateElements(root);
#if 0
if ( this->ParseObject(root, _controller, _controller) )
{
return true;
}
#endif
_isError = true;
}
}
}
#endif
return false;
}
示例3: readFractalID
bool FractalConfiguration::readFractalID(string filename, string *id, string *error)
{
XMLDocument doc;
// Parse file
doc.LoadFile(filename.c_str());
if(doc.Error())
{
*error = doc.GetErrorStr1();
return true;
}
// Get ID
XMLElement *root = doc.RootElement();
string name = string(root->Name());
if(name != "fractal")
{
*error = "Configuration file is invalid!";
return true;
}
const char* id_tmp = root->Attribute("id");
if(id_tmp == NULL)
{
*error = "Configuration file is invalid!";
return true;
}
*id = string(id_tmp);
return false;
}
示例4: cargarNiveles
void Partida::cargarNiveles() {
XMLDocument doc;
// abro XML correspondiente al mundo
bool cargoArchivo = doc.LoadFile(this->rutaMundo);
// Si no se cargo, lanzo error.
if (cargoArchivo == false) {
std::cout << "\tError al abrir el archivo XML." << std::endl;
return;
}
// obtengo nodos 'Niveles'
const XMLNode* nodo = doc.RootElement();
nodo = nodo->FirstChildElement("Niveles");
// Inicializo el contador de niveles
int i = 1;
// Cargo el primer nodo de nivel
const XMLNode* nodoNivel = nodo->FirstChildElement("Nivel");
// Mientras el nodo de nivel no es nulo, cargo los niveles.
while (nodoNivel != 0) {
// Obtengo el nodo con la ruta de archivo del nivel.
const XMLNode* nodoRuta = nodoNivel->FirstChildElement("Ruta");
// Si el nodo ruta no es nulo, cargo el nivel en la tabla
if (nodoRuta != 0) {
this->idNiveles[i] = nodoRuta->GetText();
i++; // Incremento el contador de niveles cargados
}
nodoNivel = nodoNivel->NextSiblingElement("Nivel");
}
}
示例5: paeseXml
void LoadScene::paeseXml()
{
ValueVector xmlVector;
// //xml解析
//string fileName="loadXml";
//std::string filePath = FileUtils::getInstance()->getWritablePath() + fileName;
//std::string filePath=cocos2d::FileUtils::getInstance()->getStringFromFile("loadPicture.xml");
//获取文件在系统的绝对路径
//std::string filePath1=FileUtils::getInstance()->fullPathForFilename("loadPicture.xml");
//log("%s",filePath1.c_str());
XMLDocument *pDoc = new XMLDocument();
Data fileData=FileUtils::getInstance()->getDataFromFile("loadPicture.xml");
pDoc->Parse((const char*)fileData.getBytes());//开始解析
// XMLError errorId = pDoc->LoadFile(filePath1.c_str());
// if (errorId != 0) {
// //xml格式错误
// log("cuowu");
// }
//获取第一个节点属性
XMLElement *rootEle = pDoc->RootElement();
const XMLAttribute *attribute = rootEle->FirstAttribute();
//打印节点属性名和值
log("attribute<em>name = %s,attribute</em>value = %s", attribute->Name(), attribute->Value());
loadXmlElement(rootEle);
delete pDoc;
}
示例6: LoadXml
bool ReverbsXml::LoadXml(string file)
{
XMLDocument doc;
XMLError e = doc.LoadFile(file.c_str());
if (e != XML_SUCCESS) return false;
XMLElement* root = doc.RootElement();
if (!root) return false;
// clear
revs.clear();
revmap.clear();
// base
XMLElement* b = root->FirstChildElement("base");
if (b)
GetParams(b, base);
/// revs
int i=1; //0 = none
XMLElement* n = root->FirstChildElement("rev");
while (n)
{
ReverbSet r;
GetParams(n, r);
revs.push_back(r);
revmap[r.name] = i++;
n = n->NextSiblingElement("rev");
}
return true;
}
示例7: LoadXml
bool UserXml::LoadXml(std::string file)
{
XMLDocument doc;
XMLError e = doc.LoadFile(file.c_str());
if (e != XML_SUCCESS) return false;
XMLElement* root = doc.RootElement();
if (!root) return false;
// clear
trks.clear(); trkmap.clear();
// tracks
const char* a; //int i=1; //0 = none
XMLElement* eTrk = root->FirstChildElement("track");
while (eTrk)
{
UserTrkInfo t;
a = eTrk->Attribute("n"); if (a) t.name = string(a);
a = eTrk->Attribute("date"); if (a) t.last = s2dt(a);
a = eTrk->Attribute("rate"); if (a) t.rating = s2i(a);
a = eTrk->Attribute("laps"); if (a) t.laps = s2i(a);
a = eTrk->Attribute("time"); if (a) t.time = s2r(a);
trks.push_back(t);
trkmap[t.name] = trks.size(); //i++;
eTrk = eTrk->NextSiblingElement("track");
}
return true;
}
示例8: XmlReader
TEST(XML_READER, CreateWithXMLDocument)
{
XMLDocument * doc = XmlWrapper::loadDocument("UT/TestFiles/PDDB/test_pddb_2.xml");
XMLElement * doc_element = doc->RootElement();
XmlReader * reader = new XmlReader(doc);
EXPECT_EQ(doc_element, reader->getCurrElement());
delete reader;
delete doc;
}
示例9: mazeFromXML
Maze* Maze::mazeFromXML(const std::string& filename) {
Maze* newMaze = nullptr;
try {
XMLDocument doc;
if (doc.LoadFile(filename.c_str()) == XML_SUCCESS) {
XMLElement* root = doc.RootElement();
if (!root || std::string(root->Name()).compare("maze") != 0) {
throw std::runtime_error("Maze::mazeFromXML(): Not a maze file.");
}
XMLElement* floorElement = root->FirstChildElement("floor");
if (!floorElement) {
throw std::runtime_error("Maze::mazeFromXML(): Empty maze.");
}
newMaze = new Maze();
while (floorElement && newMaze->getFloorCount() < Maze::MAX_FLOORS) {
if (!floorElement->GetText()) {
throw std::runtime_error("Maze::mazeFromXML(): Empty floor element.");
}
Map* floor = Map::mapFromXML(floorElement->GetText());
if (!floor) {
throw std::runtime_error("Maze::mazeFromXML(): Could not load a floor.");
}
newMaze->floors.push_back(floor);
floorElement = floorElement->NextSiblingElement("floor");
}
if (floorElement) {
// There was more than MAX_FLOORS floors. Best report it.
writeToLog(MessageLevel::WARNING, "Maze::mazeFromXML(): More than 256 floors specified for the maze. Stop this madness!");
}
newMaze->scanForEntrances();
}
}
catch (std::exception& e) {
if (newMaze) {
delete newMaze;
newMaze = nullptr;
}
writeToLog(MessageLevel::ERROR, "%s\n", e.what());
}
return newMaze;
}
示例10: getPathImagenSuelo
std::string Partida::getPathImagenSuelo() {
XMLDocument doc;
bool cargoArchivo = doc.LoadFile(idNiveles[contadorNiveles]);
if (cargoArchivo == false) {
std::cout << "\tError al abrir el archivo XML." << std::endl;
return std::string();
}
const XMLNode* nodo = doc.RootElement();
const XMLNode* esc = nodo->FirstChildElement("Escenario");
const XMLNode* imagenSuelo = esc->FirstChildElement("ImagenSuelo");
return imagenSuelo->GetText();
}
示例11: LoadTriggersConfig
void TriggerManager::LoadTriggersConfig(const std::string& moduleDir, std::vector<TriggerParameters>& trigsParams)
{
trigsParams.clear();
std::string file(moduleDir + "triggersConfig.xml");
XMLDocument doc;
if(doc.LoadFile(file.c_str()) != XML_SUCCESS)
{
throw -1;
}
XMLElement* root = doc.RootElement();
// Look for first trigger
XMLElement* firstTrigger = root->FirstChildElement("Trigger");
// Read all triggers
for(XMLElement* trigger = firstTrigger; trigger != nullptr; trigger = trigger->NextSiblingElement())
{
TriggerParameters trigParams;
// Get trigger id
trigParams.sensorId = std::atoi(trigger->Attribute("sensorId"));
// Get trigger type
trigParams.type = Util::Enums::TriggerTypeFromString(trigger->Attribute("sensorType"));
// Read xml elements
XMLElement* threshold = trigger->FirstChildElement("Threshold");
XMLElement* scanTime = trigger->FirstChildElement("ScanTime");
XMLElement* maskTime = trigger->FirstChildElement("MaskTime");
XMLElement* response = trigger->FirstChildElement("Response");
trigParams.threshold = (short) std::atoi(threshold->GetText());
trigParams.scanTime = (unsigned int) std::atoi(scanTime->GetText());
trigParams.maskTime = std::atoi(maskTime->GetText());
trigParams.response = Util::Enums::CurveTypeFromString(response->GetText());
//XXX Reading only sensor type
LoadSensorsConfig(moduleDir, trigParams.sensorType);
//trigParams.sensorType = IO::SensorType::Hdd;
trigsParams.push_back(trigParams);
}
return;
}
示例12: decompose
DecompositionPtr GraphMl::decompose(const Instance& instance) const
{
using namespace tinyxml2;
XMLDocument doc;
if(doc.LoadFile(optFile.getValue().c_str()))
error(doc.ErrorName());
XMLElement* graphml = doc.RootElement();
if(!graphml)
error("No root element");
XMLElement* graph = graphml->FirstChildElement("graph");
if(!graph)
error("No graph element");
// XXX We assume the GraphML file has nodes and edges ordered as in a post-order traversal
std::stack<DecompositionPtr> nodes;
XMLElement* rootNode = graph->FirstChildElement("node");
nodes.emplace(new Decomposition(bagOfNode(rootNode), app.getSolverFactory()));
const XMLElement* element = rootNode;
while((element = element->NextSiblingElement()) != nullptr) {
if(strcmp(element->Name(), "node") == 0)
nodes.emplace(new Decomposition(bagOfNode(element), app.getSolverFactory()));
else if(strcmp(element->Name(), "edge") == 0) {
if(nodes.size() < 2)
error("Not enough nodes declared before edges");
const DecompositionPtr to = nodes.top();
nodes.pop();
const DecompositionPtr& from = nodes.top();
from->addChild(std::move(to));
}
else
error("Unexpected element");
}
if(nodes.size() != 1)
error("Not all non-root nodes connected to parents");
DecompositionPtr root = nodes.top();
if(optAddEmptyLeaves.isUsed())
addEmptyLeaves(*root, app);
if(optAddEmptyRoot.isUsed())
root = addEmptyRoot(std::move(root), app);
root->setRoot();
return root;
}
示例13: cargarNombreMundos
void PanelMundo::cargarNombreMundos() {
/* En el directorio donde se encuentra el ejecutable, se almacenará un
* archivo donde se encuentran todos los mundos que ha creado el diseñador.
* Ese archivo se llamará "mundos.xml"
*/
XMLDocument doc;
bool seAbrio = doc.LoadFile(pathFileMundos);
// Si el archivo no existe, lo creo y salgo sin cargar mundos
if (!seAbrio) {
this->crearArchivoMundos();
return;
}
// Obtengo el nodo raiz
XMLNode* root = doc.RootElement();
// Si es nulo, salgo sin realizar nada
if (root == 0)
return;
// Obtengo el primer nodo del mundo
const XMLNode* nodoMundo = root->FirstChildElement("Mundo");
// Mientras el nodo de mundo no es nulo, cargo los mundos.
while (nodoMundo != 0) {
// Obtengo el nodo con el nombre del Mundo.
const XMLNode* nodoNombre = nodoMundo->FirstChildElement("Nombre");
std::string nombreMundo = nodoNombre->GetText();
// Obtengo el atributo de la cantidad de jugadores
int cantJugadores;
const char* aCJ = nodoMundo->Attribute("cantJugadores", &cantJugadores);
if (aCJ != 0) {
std::string sCantJug = cfd::intToString(cantJugadores);
nombreMundo += " (" + sCantJug;
// Si la cantidad de jugadores es 1
if (cantJugadores == 1) {
nombreMundo += " jugador)";
} else {
nombreMundo += " jugadores)";
}
}
// Obtengo el nodo con la ruta de archivo del mundo.
const XMLNode* nodoRuta = nodoMundo->FirstChildElement("Ruta");
// Si los nodos no son nulos, cargo el mundo a la tabla
if ((nodoNombre != 0) && (nodoRuta != 0)) {
nombreMundos[nombreMundo] = nodoRuta->GetText();
}
// Obtengo el siguiente nodo Mundo
nodoMundo = nodoMundo->NextSiblingElement("Mundo");
}
}
示例14: guardarCaracteristicasEscenario
void PanelEscenario::guardarCaracteristicasEscenario() const {
// Abro el archivo asociado al nivel
XMLDocument doc;
doc.LoadFile(this->rutaNivel);
// Obtengo el nodo raiz, que en teoria es el llamado Nivel.
XMLNode* nivelNode = doc.RootElement();
// Limpio el nodo de nivel
this->limpiarNodoNivel(nivelNode);
// Creo un nuevo nodo del escenario y cargo los atributos básicos.
XMLNode* escenarioNode = new XMLNode("Escenario");
// Convierto los valores flotantes a string.
std::string sAncho = cfd::floatToString(anchoFlotante);
std::string sAlto = cfd::floatToString(altoFlotante);
// Seteo los atributos del nodo del escenario.
escenarioNode->SetAttribute("ancho", sAncho);
escenarioNode->SetAttribute("alto", sAlto);
// Creo el nodo de la imagen del fondo.
XMLNode* imageFondoNode = new XMLNode("ImagenFondo");
XMLText* imageFondoText = new XMLText(rutaFondo);
imageFondoNode->LinkEndChild(imageFondoText);
// Creo el nodo de la imagen del suelo.
XMLNode* imageSueloNode = new XMLNode("ImagenSuelo");
// FIXME(eze) Esperar a que Tomás agrege el suelo para serializarlo en el XML.
XMLText* imageSueloText = new XMLText(rutaSuelo);
imageSueloNode->LinkEndChild(imageSueloText);
// Creo el nodo con la cantidad de jugadores.
XMLNode* jugadoresNode = new XMLNode("Jugadores");
// Convierto el numero de jugadores a string.
std::string sJugadores = cfd::intToString(cantidadJugadores);
XMLText* jugadoresText = new XMLText(sJugadores);
jugadoresNode->LinkEndChild(jugadoresText);
// Linkeo los atributos del Escenario
escenarioNode->LinkEndChild(imageFondoNode);
escenarioNode->LinkEndChild(imageSueloNode);
escenarioNode->LinkEndChild(jugadoresNode);
// Linkeo el nodo de escenario en el nodo del nivel.
nivelNode->LinkEndChild(escenarioNode);
// Guardo el documento.
doc.SaveFile();
}
示例15:
Armature* CCDragonBones::buildArmature(const char* skeletonXMLFile,
const char* textureXMLFile,
const char* dragonBonesName,
const char* armatureName,
const char* animationName)
{
XMLDataParser parser;
XMLDocument doc;
doc.LoadFile(skeletonXMLFile);
Cocos2dxFactory fac;
fac.addSkeletonData(parser.parseSkeletonData(doc.RootElement()) );
XMLDocument doc1;
doc1.LoadFile(textureXMLFile);
fac.addTextureAtlas(new Cocos2dxTextureAtlas(parser.parseTextureAtlasData(doc1.RootElement())));
return fac.buildArmature(armatureName, animationName ,dragonBonesName);
}