本文整理汇总了C++中TiXmlHandle::Element方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlHandle::Element方法的具体用法?C++ TiXmlHandle::Element怎么用?C++ TiXmlHandle::Element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlHandle
的用法示例。
在下文中一共展示了TiXmlHandle::Element方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flushNodeSrvs
int MetaConfig::flushNodeSrvs(TiXmlHandle *meta)
{
std::vector<NodeService> tmp;
TiXmlHandle srvs = meta->FirstChildElement("services");
if(srvs.Element()){
TiXmlHandle srv = srvs.FirstChildElement("service");
while(srv.Element()){
NodeService ns;
loadInt(&srv, "gid", ns.gid, -1);
loadString(&srv, "name", ns.service, "");
loadString(&srv, "ip", ns.ip, "");
loadInt(&srv, "port", ns.port, -1);
if(!(ns.gid != -1 && !ns.service.empty() && !ns.ip.empty() && ns.port != -1)){
std::cerr << "load service error name:" << ns.service << " ip:" << ns.ip << " port:" << ns.port << " node:" << ns.gid<< std::endl;
return -1;
}
tmp.push_back(ns);
srv = srv.Element()->NextSibling("service");
}
std::sort(tmp.begin(), tmp.end());
std::unique(tmp.begin(), tmp.end());
}
boost::mutex::scoped_lock lock(mtx);
ndSrvs.swap(tmp);
return 0;
}
示例2: initFromXML
void Plan::initFromXML(TiXmlHandle hObj){
double x1, y1, z1;
double x2, y2, z2;
double x3, y3, z3;
double x4, y4, z4;
Objet::initFromXML(hObj);
TiXmlElement* pElem=hObj.Element();
pElem->QueryDoubleAttribute("x1", &x1);
pElem->QueryDoubleAttribute("y1", &y1);
pElem->QueryDoubleAttribute("z1", &z1);
pElem->QueryDoubleAttribute("x2", &x2);
pElem->QueryDoubleAttribute("y2", &y2);
pElem->QueryDoubleAttribute("z2", &z2);
pElem->QueryDoubleAttribute("x3", &x3);
pElem->QueryDoubleAttribute("y3", &y3);
pElem->QueryDoubleAttribute("z3", &z3);
pElem->QueryDoubleAttribute("x4", &x4);
pElem->QueryDoubleAttribute("y4", &y4);
pElem->QueryDoubleAttribute("z4", &z4);
this->setU(vector3(x1,y1,z1));
this->setV(vector3(x2,y2,z2));
this->setW(vector3(x3,y3,z3));
this->setX(vector3(x4,y4,z4));
}
示例3: parseXmlFile
void SyncXmlParser::parseXmlFile()
{
printDebugMessage("parsing xml file", STATUS);
TiXmlDocument doc(xml_file_name.c_str());
bool load_ok = doc.LoadFile();
if(load_ok)
{
printDebugMessage("file loaded: " + xml_file_name, INFO);
}
else
{
printDebugMessage("file load error: " + xml_file_name, INFO);
exit(1);
}
TiXmlHandle doc_handle(&doc);
TiXmlHandle sync = doc_handle.ChildElement("sync", 0);
if(sync.Element())
{
TiXmlHandle streams = sync.ChildElement("streams", 0);
TiXmlHandle general = sync.ChildElement("general", 0);
if(streams.Element())
{
TiXmlHandle dvb = streams.ChildElement("dvb", 0);
cout << dvb.ChildElement("active", 0).Element()->Value() << ": " << dvb.ChildElement("active", 0).Element()->GetText() << endl;
int number_of_p2ps = 0;
for(int i=0; i<30; i++)
{
TiXmlHandle p2p = streams.ChildElement("p2p", i);
if(p2p.Element())
{
number_of_p2ps++;
}
else
{
break;
}
}
cout << "number of p2p streams: " << number_of_p2ps << endl;
}
if(general.Element())
{
}
}
}
示例4: load
void TinyXmlServerConfigImp::load(FILE *fp){
loaded = true;
TiXmlDocument doc;
doc.LoadFile(fp);
TiXmlHandle docH( &doc );
TiXmlHandle servers = docH.FirstChildElement( "conf" ).FirstChildElement( "servers" );
if(servers.Element()){
TiXmlHandle server = servers.FirstChildElement(serverElem.data());
if(server.Element()){
loadServer(server);
}else{
log(Fatal, "%s config not found", serverElem.data());
exit(-1);
}
}else{
log(Error, "servers element is NULL");
}
forEachWatcher0(&IServerConfigWatcher::onConfigRefresh);
}
示例5: initFromXML
void PointLumiere::initFromXML(TiXmlHandle hObj){
double x,y,z;
TiXmlElement* pElem=hObj.Element();
Lumiere::initFromXML(hObj);
pElem->QueryDoubleAttribute("x", &x);
pElem->QueryDoubleAttribute("y", &y);
pElem->QueryDoubleAttribute("z", &z);
this->position.Set(x,y,z);
this->falloff[0]=1.0;
this->falloff[1]=0.0;
this->falloff[2]=0.0;
}
示例6: DoInitWizard
bool wxTreeMultiXmlMapper::DoInitWizard(const wxString &start_tag)
{
bool allok = false;
// clean up the control first
m_ctrl->DeleteAllItems();
// reset the ID counter
m_currentId = XMLMAP_BASE_ID;
// obtain handle to document
TiXmlHandle h(m_tiDoc);
// find our first wizard declaration
TiXmlHandle wizard = h.FirstChildElement(start_tag.c_str());
// we expect it to be an element, and we should go from there with
// parsing categories and other stuff..
if(wizard.Element())
{
// we skip all and look for the first category element
TiXmlElement *cat = wizard.FirstChildElement(XMLMAP_TAG_CATEGORY).Element();
// go through the loop of creating all categories
allok = (cat != 0);
while(cat && allok)
{
// ok create a category root name, but only when we
// have a name to give it
if(cat->Attribute(XMLMAP_ATTR_CAPTION))
{
wxTreeMultiItem item = AddCategory(cat, wxTreeMultiItem(0));
allok = DoCreateControls(cat, item, 0, 0);
}
// find a next one
if(allok)
cat = cat->NextSiblingElement(XMLMAP_TAG_CATEGORY);
}
}
return allok;
}
示例7: reload
int MetaConfig::reload()
{
FILE *fp = fopen(fname.c_str(), "r");
if(!fp){
log(Warn, "reload file %s error", fname.c_str());
return -1;
}
TiXmlDocument doc;
doc.LoadFile(fp);
TiXmlHandle docH( &doc );
TiXmlHandle meta = docH.FirstChildElement( "conf" ).FirstChildElement( "servers" ).FirstChildElement("meta");
if(meta.Element()){
loadBool(&meta, "sync", bsync, false);
TiXmlHandle daemon = meta.FirstChildElement("daemon");
int ret = flushNodeSrvs(&daemon);
return ret;
}else{
fclose(fp);
return -1;
}
}
示例8: reload
void TileSet::reload()
{
// XML-Dokument laden
std::string text = FileSystem::inst().readStringFromFile(filename);
TiXmlDocument doc;
doc.Parse(text.c_str());
if(doc.ErrorId())
{
printfLog("+ ERROR: Could not parse tileset XML file \"%s\" (Error: %d).\n",
filename.c_str(),
doc.ErrorId());
error = 1;
return;
}
TiXmlHandle docHandle(&doc);
TiXmlHandle tileSetHandle = docHandle.FirstChildElement("TileSet");
TiXmlElement* p_tileSetElement = tileSetHandle.Element();
// Dateiname des Bilds und Größe der Tiles lesen
const char* p_imageFilename = p_tileSetElement->Attribute("image");
p_tileSetElement->Attribute("tileWidth", &tileSize.x);
p_tileSetElement->Attribute("tileHeight", &tileSize.y);
// Textur laden
std::string dir = FileSystem::inst().getPathDirectory(filename);
std::string imageFilename = dir + (dir.empty() ? "" : "/") + std::string(p_imageFilename);
p_texture = Manager<Texture>::inst().request(imageFilename);
if(!p_texture)
{
printfLog("+ ERROR: Could not load tileset texture \"%s\" for tileset \"%s\".\n",
p_imageFilename,
filename.c_str());
error = 2;
return;
}
p_texture->keepInMemory();
maxTileID = 0;
// alle Kind-Elemente verarbeiten
TiXmlElement* p_tileElement = p_tileSetElement->FirstChildElement("Tile");
while(p_tileElement)
{
TileInfo info = badTile;
// ID lesen
uint id = static_cast<uint>(p_tileElement->Attribute("id")[0]);
maxTileID = max(maxTileID, id);
// Position lesen
p_tileElement->Attribute("x", &info.position.x);
p_tileElement->Attribute("y", &info.position.y);
// Typ lesen
p_tileElement->Attribute("type", &info.type);
if(info.type == 2)
{
// Zerstörzeit lesen
p_tileElement->Attribute("destroyTime", &info.destroyTime);
// Trümmerfarbe berechnen
info.debrisColor = DebrisColorDB::inst().getDebrisColor(p_texture, info.position);
}
// Tile-Typ eintragen
tiles[id] = info;
p_tileElement = p_tileElement->NextSiblingElement("Tile");
}
}
示例9: reload
void Font::reload()
{
cleanUp();
// XML-Dokument laden
std::string text = FileSystem::inst().readStringFromFile(filename);
TiXmlDocument doc;
doc.Parse(text.c_str());
if(doc.ErrorId())
{
printfLog("+ ERROR: Could not parse font XML file \"%s\" (Error: %d).\n",
filename.c_str(),
doc.ErrorId());
error = 1;
return;
}
TiXmlHandle docHandle(&doc);
TiXmlHandle fontHandle = docHandle.FirstChildElement("Font");
TiXmlElement* p_fontElement = fontHandle.Element();
// Dateiname des Bilds, Zeilenhöhe und Offset lesen
const char* p_imageFilename = p_fontElement->Attribute("image");
p_fontElement->Attribute("lineHeight", &lineHeight);
p_fontElement->Attribute("offset", &offset);
// alle Kind-Elemente verarbeiten
TiXmlElement* p_charElement = p_fontElement->FirstChildElement("Character");
while(p_charElement)
{
int code, x, y, w, h;
p_charElement->Attribute("code", &code);
p_charElement->Attribute("x", &x);
p_charElement->Attribute("y", &y);
p_charElement->Attribute("w", &w);
p_charElement->Attribute("h", &h);
if(code >= 0 && code < 256)
{
charInfo[code].position = Vec2i(x, y);
charInfo[code].size = Vec2i(w, h);
}
p_charElement = p_charElement->NextSiblingElement("Character");
}
// Textur laden
std::string dir = FileSystem::inst().getPathDirectory(filename);
std::string imageFilename = dir + (dir.empty() ? "" : "/") + std::string(p_imageFilename);
p_texture = Manager<Texture>::inst().request(imageFilename);
if(!p_texture)
{
printfLog("+ ERROR: Could not load font texture \"%s\" for font \"%s\".\n",
p_imageFilename,
filename.c_str());
error = 2;
return;
}
// Cache leeren
stringCache.clear();
listFree = ~0;
}
示例10: readSettings
void CameraEngine::readSettings() {
config.device = 0;
config.color = false;
config.compress = false;
config.cam_width = SETTING_MAX;
config.cam_height = SETTING_MAX;
config.cam_fps = SETTING_MAX;
config.frame = false;
config.frame_xoff = 0;
config.frame_yoff = 0;
config.frame_width = SETTING_MAX;
config.frame_height = SETTING_MAX;
sprintf(config.file,"none");
sprintf(config.folder,"none");
config.brightness = SETTING_DEFAULT;
config.contrast = SETTING_DEFAULT;
config.gain = SETTING_DEFAULT;
config.gamma = SETTING_DEFAULT;
config.exposure = SETTING_DEFAULT;
config.sharpness = SETTING_DEFAULT;
config.shutter = SETTING_DEFAULT;
default_brightness = INT_MIN;
default_contrast = INT_MIN;
default_gain = INT_MIN;
default_shutter = INT_MIN;
default_exposure = INT_MIN;
default_sharpness = INT_MIN;
default_focus = INT_MIN;
default_gamma = INT_MIN;
#ifdef __APPLE__
char path[1024];
#endif
if (strcmp( config_file, "none" ) == 0) {
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef mainBundleURL = CFBundleCopyBundleURL( mainBundle);
CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
CFStringGetCString( cfStringRef, path, 1024, kCFStringEncodingASCII);
CFRelease( mainBundleURL);
CFRelease( cfStringRef);
sprintf(full_path,"%s/Contents/Resources/camera.xml",path);
config_file = full_path;
#elif !defined WIN32
if (access ("./camera.xml", F_OK )==0) config_file = "./camera.xml";
else if (access ("/usr/share/reacTIVision/camera.xml", F_OK )==0) config_file = "/usr/share/reacTIVision/camera.xml";
else if (access ("/usr/local/share/reacTIVision/camera.xml", F_OK )==0) config_file = "/usr/local/share/camera.xml";
else if (access ("/opt/share/reacTIVision/camera.xml", F_OK )==0) config_file = "/opt/share/reacTIVision/camera.xml";
#else
config_file = "./camera.xml";
#endif
}
TiXmlDocument xml_settings( config_file );
xml_settings.LoadFile();
if( xml_settings.Error() )
{
std::cout << "Error loading camera configuration file: " << config_file << std::endl;
return;
}
TiXmlHandle docHandle( &xml_settings );
TiXmlHandle camera = docHandle.FirstChild("portvideo").FirstChild("camera");
TiXmlElement* camera_element = camera.Element();
if( camera_element==NULL )
{
std::cout << "Error loading camera configuration file: " << config_file << std::endl;
return;
}
if(camera_element->Attribute("id")!=NULL) {
if (strcmp(camera_element->Attribute("id"), "auto" ) == 0) config.device=SETTING_AUTO;
else config.device = atoi(camera_element->Attribute("id"));
}
if(camera_element->Attribute("file")!=NULL) {
#ifdef __APPLE__
sprintf(config.file,"%s/../%s",path,camera_element->Attribute("file"));
#else
sprintf(config.file,"%s",camera_element->Attribute("file"));
#endif
}
if(camera_element->Attribute("folder")!=NULL) {
#ifdef __APPLE__
sprintf(config.folder,"%s/../%s",path,camera_element->Attribute("folder"));
#else
sprintf(config.folder,"%s",camera_element->Attribute("folder"));
#endif
}
TiXmlElement* image_element = camera.FirstChild("capture").Element();
if (image_element!=NULL) {
if ((image_element->Attribute("color")!=NULL) && ( strcmp( image_element->Attribute("color"), "true" ) == 0 )) config.color = true;
//.........这里部分代码省略.........
示例11: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
#ifdef TIXML_USE_STL
/* What the todo list should look like after processing.
In stream (no formatting) representation. */
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Vo‚\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
QueryPerformanceCounter( (LARGE_INTEGER*) (&start) );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
ostringstream outputStream( ostringstream::out );
{
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
doc.Print( stdout );
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
assert( node );
todoElement = node->ToElement();
assert( todoElement );
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
//.........这里部分代码省略.........
示例12: parse
int MetaConfig::parse()
{
FILE *fp = fopen(fname.c_str(), "r");
if(!fp){
std::cerr << "load file " << fname << " error" << std::endl;
return -1;
}
TiXmlDocument doc;
doc.LoadFile(fp);
TiXmlHandle docH( &doc );
TiXmlHandle meta = docH.FirstChildElement( "conf" ).FirstChildElement( "servers" ).FirstChildElement("meta");
if(meta.Element()){
std::string lip;
loadString(&meta, "ip", lip, "");
if(lip.empty())
{
ip = 0;
}
else
{
ip = sox::aton_addr(lip.c_str());
if (ip == INADDR_NONE)
{
log(Error, "invalid ip:%s", lip.c_str());
return -1;
}
}
loadInt(&meta, "session_port", sessionPort, 2001);
loadInt(&meta, "lostcheck_port", lostCheckPort, 2010);
loadInt(&meta, "snap_port", snapPort, 2014);
loadInt(&meta, "sys_port", sysPort, 2018);
loadInt(&meta, "thread", threadNum, 10);
loadInt(&meta, "psync_limit", pSyncLogLimit, 10);
pSyncLogLimit *= 1024; // kbyte-> byte
loadBool(&meta, "sync", bsync, false);
loadBool(&meta, "session_on",isSessionOn, false);
loadString(&meta, "type", type, "");
if(type == "daemon")
{
// do nothing
}
else if(type == "localDaemon")
{
// do nothing
}
else
{
std::cerr << "invalid type" << type << std::endl;
fclose(fp);
return -1;
}
if(!isLocalDaemon()) // daemon
{
TiXmlHandle daemon = meta.FirstChildElement("daemon");
TiXmlHandle node = daemon.FirstChildElement("node");
if(node.Element())
{
loadInt(&node, "gid", gid, -1);
loadInt(&node, "lid", lid, -1);
if(gid == -1 || lid == -1){
std::cerr << "read from config gid:" << gid << " lid:" << lid << " must be set" << std::endl;
fclose(fp);
return -1;
}
}
else
{
std::cerr << "xml path conf.servers.meta.node not found" << std::endl;
fclose(fp);
return -1;
}
TiXmlHandle db = daemon.FirstChildElement("db").FirstChildElement("mysql");
if(db.Element()){
loadString(&db, "host", config.host, "localhost");
loadInt(&db, "port", config.port, 3306);
loadString(&db, "user", config.user, "root");
loadString(&db, "passwd", config.passwd, "");
loadString(&db, "database", config.database, "daemon");
loadString(&db, "charset", config.charset, "utf8");
}else{
config.host = "localhost";
config.port = 3306;
config.user = "root";
config.passwd = "";
config.database = "daemon";
config.charset = "utf8";
log(Debug, "use default mysql config setting");
}
int ret = flushNodeSrvs(&daemon);
if(ret != 0){
fclose(fp);
return ret;
}
}
//.........这里部分代码省略.........
示例13: main
// exchanger sceneFile mappingsFile materialsFile
// e.g.: MaterialExchanger sample.dpbf sample_mappings.xml sample_materials.xml
int main( int argc, char *argv[] )
{
if ( argc != 3 )
{
std::cerr << "exchanger usage: exchanger sceneFile mappingsFile materialsFile\n"
<< " where sceneFile is a DP/SG-loadable scene file (*.dpbf, *.dae, ...)\n"
<< " and mappingsFile is an XML file that gives the mapping of EffectData\n"
<< " names in the scene to EffectData names in the materialsFile,\n"
<< " and materialsFile is an XML file with the EffectData to use.\n"
<< " Replaces all EffectData in the scene with a name like \"*fx\"\n"
<< " with a material from the materialsFile with the same name without \"fx\"\n";
return( -1 );
}
std::string sceneFile = argv[1];
std::string mappingsFile = argv[2];
std::string materialsFile = argv[3];
if ( !dp::util::fileExists( sceneFile ) )
{
std::cerr << "Could not find sceneFile <" << sceneFile << ">.\n";
return( -1 );
}
if ( !dp::util::fileExists( mappingsFile ) )
{
std::cerr << "Could not find mappingsFile <" << mappingsFile << ">.\n";
return( -1 );
}
if ( !dp::util::fileExists( materialsFile ) )
{
std::cerr << "Could not find materialsFile <" << materialsFile << ">.\n";
return( -1 );
}
dp::sg::ui::ViewStateSharedPtr viewState = dp::sg::io::loadScene( sceneFile );
if ( ! viewState )
{
std::cerr << "Could not load sceneFile <" << sceneFile << ">.\n";
return( -1 );
}
dp::sg::core::SceneSharedPtr scene = viewState->getScene();
if ( ! scene )
{
std::cerr << "The sceneFile <" << sceneFile << "> does not contain a Scene.\n";
return( -1 );
}
dp::sg::core::NodeSharedPtr rootNode = scene->getRootNode();
if ( ! rootNode )
{
std::cerr << "The scene in <" << sceneFile << "> does not contain a root node.\n";
return( -1 );
}
if ( ! dp::fx::EffectLibrary::instance()->loadEffects( materialsFile ) )
{
std::cerr << "Could not load materialsFile <" << materialsFile << ">.\n";
return( -1 );
}
std::unique_ptr<TiXmlDocument> doc( new TiXmlDocument( mappingsFile.c_str() ) );
if ( ! doc )
{
std::cerr << "Could not open mappingsFile <" << mappingsFile << ">.\n";
return( -1 );
}
if ( ! doc->LoadFile() )
{
std::cerr << "Could not load mappingsFile <" << mappingsFile << ">.\n";
return( -1 );
}
TiXmlHandle libraryHandle = doc->FirstChildElement( "library" ); // The required XML root node.
TiXmlElement * rootElement = libraryHandle.Element();
if ( ! rootElement )
{
std::cerr << "mappingsFile <" << mappingsFile << "> does not contain any mapping.\n";
return( -1 );
}
dp::sg::algorithm::ReplacementMapPipelineData replacementMap;
for ( TiXmlElement * element = rootElement->FirstChildElement() ; element ; element = element->NextSiblingElement() )
{
DP_ASSERT( element->Attribute( "from" ) && element->Attribute( "to" ) );
std::string from( element->Attribute( "from" ) );
std::string to( element->Attribute( "to" ) );
dp::fx::EffectDataSharedPtr effectData = dp::fx::EffectLibrary::instance()->getEffectData( to );
if ( ! effectData )
{
std::cerr << "Could no get EffectData <" << to << ".\n";
//.........这里部分代码省略.........
示例14: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
{
#ifdef TIXML_USE_STL
// What the todo list should look like after processing.
// In stream (no formatting) representation.
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Voel\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
_CrtMemCheckpoint( &startMemState );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
printf( "** Printing via doc.Print **\n" );
doc.Print( stdout );
{
printf( "** Printing via TiXmlPrinter **\n" );
TiXmlPrinter printer;
doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );
}
#ifdef TIXML_USE_STL
{
printf( "** Printing via operator<< **\n" );
std::cout << doc;
}
#endif
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
//.........这里部分代码省略.........
示例15: main
int main()
{
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
//
const char* demoStart =
"<?xml version=\"1.0\" standalone='no' >\n"
"<!-- Our to do list data -->"
"<ToDo>\n"
"<!-- Do I need a secure PDA? -->\n"
"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
"<Item priority=\"2\" distance='none'> Do bills </Item>"
"<Item priority=\"2\" distance='far & back'> Look for Evil Dinosaurs! </Item>"
"</ToDo>";
#ifdef TIXML_USE_STL
/* What the todo list should look like after processing.
In stream (no formatting) representation. */
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
"<ToDo>"
"<!-- Do I need a secure PDA? -->"
"<Item priority=\"2\" distance=\"close\">Go to the"
"<bold>Toy store!"
"</bold>"
"</Item>"
"<Item priority=\"1\" distance=\"far\">Talk to:"
"<Meeting where=\"School\">"
"<Attendee name=\"Marple\" position=\"teacher\" />"
"<Attendee name=\"Voel\" position=\"counselor\" />"
"</Meeting>"
"<Meeting where=\"Lunch\" />"
"</Item>"
"<Item priority=\"2\" distance=\"here\">Do bills"
"</Item>"
"</ToDo>";
#endif
// The example parses from the character string (above):
#if defined( WIN32 ) && defined( TUNE )
QueryPerformanceCounter( (LARGE_INTEGER*) (&start) );
#endif
{
// Write to a file and read it back, to check file I/O.
TiXmlDocument doc( "demotest.xml" );
doc.Parse( demoStart );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
}
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
printf( "** Demo doc read from disk: ** \n\n" );
doc.Print( stdout );
TiXmlNode* node = 0;
TiXmlElement* todoElement = 0;
TiXmlElement* itemElement = 0;
// --------------------------------------------------------
// An example of changing existing attributes, and removing
// an element from the document.
// --------------------------------------------------------
// Get the "ToDo" element.
// It is a child of the document, and can be selected by name.
node = doc.FirstChild( "ToDo" );
assert( node );
todoElement = node->ToElement();
assert( todoElement );
// Going to the toy store is now our second priority...
// So set the "priority" attribute of the first item in the list.
node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
assert( node );
itemElement = node->ToElement();
assert( itemElement );
itemElement->SetAttribute( "priority", 2 );
// Change the distance to "doing bills" from
// "none" to "here". It's the next sibling element.
itemElement = itemElement->NextSiblingElement();
assert( itemElement );
//.........这里部分代码省略.........