本文整理汇总了C++中TiXmlHandle::Child方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlHandle::Child方法的具体用法?C++ TiXmlHandle::Child怎么用?C++ TiXmlHandle::Child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlHandle
的用法示例。
在下文中一共展示了TiXmlHandle::Child方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processImage
Image processImage(TiXmlHandle& item) {
// Quiz: rewite with FirstChild(<name>) instead
TiXmlElement* url = item.Child(0).ToElement();
TiXmlElement* id = item.Child(1).ToElement();
TiXmlElement* source_url = item.Child(2).ToElement();
Image image;
image.url = std::string(url->GetText());
image.id = std::string(id->GetText());
image.source_url = std::string(source_url->GetText());
return image;
}
示例2: processXmlDocument
// ------------------------------------------------------------------------------------------------
void processXmlDocument(TiXmlHandle& handler, std::vector<Image>* array) {
TiXmlHandle images = handler.FirstChild("response").FirstChild("data").FirstChild("images");
TiXmlHandle item_1 = images.Child("image", 0);
TiXmlHandle item_2 = images.Child("image", 1);
TiXmlHandle item_3 = images.Child("image", 2);
Image image_1 = processImage(item_1);
Image image_2 = processImage(item_2);
Image image_3 = processImage(item_3);
array->push_back(image_1);
array->push_back(image_2);
array->push_back(image_3);
}
示例3: readTag
//---------------------------------------------------------
bool ofXMLSettings::readTag(string tag, char * valueString, int which){
vector<string> tokens = tokenize(tag,":");
TiXmlHandle tagHandle = *storedHandle;
for(int x=0;x<tokens.size();x++){
if(x == 0)tagHandle = tagHandle.ChildElement(tokens.at(x), which);
else tagHandle = tagHandle.FirstChildElement( tokens.at(x) );
}
// once we've walked, let's get that value...
TiXmlHandle valHandle = tagHandle.Child( 0 );
//now, clear that vector!
tokens.clear();
// if that value is really text, let's get the value out of it !
if (valHandle.Text()){
int maxLen = MIN(MAX_TAG_VALUE_LENGTH_IN_CHARS, strlen(valHandle.Text()->Value()));
memcpy(valueString, valHandle.Text()->Value(), maxLen);
return true;
} else {
return false;
}
}
示例4: __setupCalibration
//--------------------------------------------------------------
void ofxMagneticApp::__setupCalibration()
{
// Get calibration points from XML
TiXmlHandle hDoc(&__calibrationXML);
TiXmlHandle hCalibration = hDoc.FirstChild("calibration");
// Initialize arrays
__calibrationCameraPoints = new ofPoint[__calibrationPointCount];
__calibrationScreenPoints = new ofPoint[__calibrationPointCount];
__calibrationTriangles = new int[__calibrationTriangleCount];
// Find distance between lines in grid
float deltaX = (float)__captureWidth / (float)(__calibrationColumns - 1);
float deltaY = (float)__captureHeight / (float)(__calibrationRows - 1);
// Iterate through rows
int t = 0;
for (int i = 0; i < __calibrationRows; i++)
{
// Iterate through columns
for (int j = 0; j < __calibrationColumns; j++)
{
// Omit last point in triangle mesh
if (i < __calibrationRows - 1 && j < __calibrationColumns - 1)
{
// Create a downward pointing right triangle on left side of rectangle
__calibrationTriangles[t + 0] = (j + 0) + (i + 0) * __calibrationColumns;
__calibrationTriangles[t + 1] = (j + 1) + (i + 0) * __calibrationColumns;
__calibrationTriangles[t + 2] = (j + 0) + (i + 1) * __calibrationColumns;
t += 3;
// And an upward pointing right triangle on right side of the rectangle
__calibrationTriangles[t + 0] = (j + 1) + (i + 0) * __calibrationColumns;
__calibrationTriangles[t + 1] = (j + 1) + (i + 1) * __calibrationColumns;
__calibrationTriangles[t + 2] = (j + 0) + (i + 1) * __calibrationColumns;
t += 3;
}
// Calculate point index
int index = i * __calibrationColumns + j;
// Get calibration point from XML
TiXmlElement* pPoint = hCalibration.Child("point", index).ToElement();
// Set grid point on screen and camera
__calibrationScreenPoints[index].set(deltaX * (float)j, deltaY * (float)i);
__calibrationCameraPoints[index].set(atof(pPoint->Attribute("x")) * (float)__captureWidth, atof(pPoint->Attribute("y")) * (float)__captureHeight);
}
}
}
示例5: readTag
//---------------------------------------------------------
bool ofxXmlSettings::readTag(const string& tag, TiXmlHandle& valHandle, int which){
vector<string> tokens = tokenize(tag,":");
TiXmlHandle tagHandle = storedHandle;
for(int x=0;x<(int)tokens.size();x++){
if(x == 0)tagHandle = tagHandle.ChildElement(tokens.at(x), which);
else tagHandle = tagHandle.FirstChildElement( tokens.at(x) );
}
// once we've walked, let's get that value...
valHandle = tagHandle.Child( 0 );
return (valHandle.ToText() != NULL);
}
示例6: getIt
bool OutputFile::getIt(ParamQt * p)
{
int deb=0;
currentIteration++;
p->setRho(0);
p->setTheta(0);
p->setLL(0);
TiXmlHandle root(&mDoc);
TiXmlHandle h = root.FirstChild("outputFile");
TiXmlHandle hIter = h.Child("Iteration", currentIteration);
TiXmlElement* t;
// <Tree>
t = hIter.FirstChild("Tree").ToElement();
if (t == NULL) // Can I use hIter to return false?
return false;
string s(t->GetText());
while (s.at(0)==10 || s.at(0)==13) s=s.substr(1,s.length()-1);
while (s.at(s.size()-1)==10 || s.at(s.size()-1)==13) s=s.substr(0,s.length()-1);
p->setTreeData(new RecTree(getL(),s,false,false),blocks);
// <number>, <theta>, <delta>, <rho>, <ll>.
t = hIter.FirstChild("number").ToElement(); p->setNumber(atol(t->GetText()));
t = hIter.FirstChild("theta").ToElement(); p->setTheta(p->getTheta() + atof(t->GetText()));
t = hIter.FirstChild("delta").ToElement(); p->setDelta(atof(t->GetText()));
t = hIter.FirstChild("rho").ToElement(); p->setRho(p->getRho() + atof(t->GetText()));
t = hIter.FirstChild("ll").ToElement(); p->setLL(p->getLL() + atof(t->GetText()));
// <recedge>
TiXmlElement* parent = hIter.ToElement();
TiXmlElement* child = 0;
while (child = (TiXmlElement*) parent->IterateChildren("recedge", child))
{
int start=0,end=0,efrom=0,eto=0;
double ato=0,afrom=0;
t = child->FirstChildElement("start"); start = deb + atoi(t->GetText());
t = child->FirstChildElement("end"); end = deb + atoi(t->GetText());
t = child->FirstChildElement("efrom"); efrom = atoi(t->GetText());
t = child->FirstChildElement("eto"); eto = atoi(t->GetText());
t = child->FirstChildElement("afrom"); afrom = atof(t->GetText());
t = child->FirstChildElement("ato"); ato = atof(t->GetText());
p->getTree()->addRecEdge(afrom,ato,start,end,efrom,eto);
}
return true;
}
示例7: 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" );
//.........这里部分代码省略.........
示例8: loadMap
bool Map::loadMap(const std::string &filename)
{
std::string file = resourceManager->getDataPath(filename);
logger->logDebug("Loading map " + file);
TiXmlDocument doc(file.c_str());
bool loaded = doc.LoadFile();
if (!loaded)
{
logger->logError("Error loading map");
return false;
}
TiXmlHandle hDoc(&doc);
TiXmlElement *e;
TiXmlHandle map = hDoc.FirstChild("map");
if (!loadMapInfo(map.ToElement()))
{
return false;
}
int numTilesets = 0;
while(1)
{
e = map.Child("tileset", numTilesets).ToElement();
if (!loadTileset(e))
{
break;
}
++numTilesets;
}
if (numTilesets == 0)
{
logger->logError("No tilesets found.");
return false;
}
int numLayers = 0;
while(1)
{
e = map.Child("layer", numLayers).ToElement();
if (!loadLayer(e))
{
break;
}
++numLayers;
}
if (numLayers == 0)
{
logger->logError("No layers found!");
return false;
}
logger->logDebug("Finished loading map");
mLoaded = true;
return true;
}
示例9: 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 );
//.........这里部分代码省略.........
示例10: ReadElementText
wxString XmlUtil::ReadElementText(TiXmlHandle handle, const char* elementName, const wxString& defaultValue) {
TiXmlElement* element = handle.Child(elementName, 0).ToElement();
if (element) return wxString(element->GetText(), wxConvUTF8);
return defaultValue;
}