本文整理汇总了C++中XMLDocument::InsertEndChild方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLDocument::InsertEndChild方法的具体用法?C++ XMLDocument::InsertEndChild怎么用?C++ XMLDocument::InsertEndChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLDocument
的用法示例。
在下文中一共展示了XMLDocument::InsertEndChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: example_5
void example_5()
{
printf( "XML Example 5\n" );
// Test: Programmatic DOM
// Build:
// <element>
// <!--comment-->
// <sub attrib="1" />
// <sub attrib="2" />
// <sub attrib="3" >& Text!</sub>
// <element>
XMLDocument* doc = new XMLDocument();
XMLNode* element = doc->InsertEndChild( doc->NewElement( "element" ) );
XMLElement* sub[3] = { doc->NewElement( "sub" ), doc->NewElement( "sub" ), doc->NewElement( "sub" ) };
for( int i=0; i<3; ++i ) {
sub[i]->SetAttribute( "attrib", i );
}
element->InsertEndChild( sub[2] );
XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
element->InsertAfterChild( comment, sub[0] );
element->InsertAfterChild( sub[0], sub[1] );
sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
doc->Print();
doc->SaveFile( "pretty.xml" );
doc->SaveFile( "compact.xml", true );
delete doc;
}
示例2: newHighScore
void highscore::newHighScore(score *newHighScore)
{
// SAVE NEW SCORE DIRECTLY INTO XML FILE
// Load XML file
char scoreStr[10];
XMLDocument doc;
XMLElement *nodeTransversal;
doc.LoadFile("score.xml");
// Write its child first
XMLText *nameText = doc.NewText(newHighScore->readPlayerName().c_str());
XMLElement *name = doc.NewElement("name");
name->InsertEndChild(nameText);
sprintf(scoreStr, "%d", newHighScore->readScore());
XMLText *scoreText = doc.NewText(scoreStr);
XMLElement *score = doc.NewElement("score");
score->InsertEndChild(scoreText);
// Create new node
XMLElement* hs = doc.NewElement("hs");
hs->InsertEndChild(name);
hs->InsertEndChild(score);
doc.InsertEndChild(hs);
doc.SaveFile("score.xml");
}
示例3: vFile
bool CGBFile<GeomType, ValueType>::save(const std::string& directoryname, const std::string& fn, const Volume3d<GeomType, ValueType>& volume)
{
const std::string& filename = directoryname + "/" + fn;
XMLDocument xml;
XMLDeclaration* decl = xml.NewDeclaration();
xml.InsertEndChild(decl);
XMLNode* root = xml.NewElement("root");
xml.InsertEndChild(root);
{
XMLElement* res = xml.NewElement(resStr.c_str());
res->SetAttribute("x", volume.getResolutions()[0]);
res->SetAttribute("y", volume.getResolutions()[1]);
res->SetAttribute("z", volume.getResolutions()[2]);
root->InsertEndChild(res);
}
root->InsertEndChild( create(xml, originStr, volume.getStart()) );
root->InsertEndChild( create(xml, "length", volume.getSpace().getLengths()));
imageFileNames.clear();
{
XMLElement* e = xml.NewElement("volume");
e->SetAttribute("type", "unsigned char");
e->SetAttribute("format", "png");
VolumeFile vFile(directoryname);
for (size_t i = 0; i < volume.getResolutions()[2]; ++i) {
const auto iFile = vFile.toImageFile( "image", i, ImageFile::Type::PNG);
XMLElement* elem = xml.NewElement("image");
const auto& str = iFile.getFileNameIncludingPath();
elem->SetAttribute("path", str.c_str());
e->InsertEndChild(elem);
imageFileNames.push_back(str);
}
root->InsertEndChild(e);
}
//for (size_t i = 0; i < )
xml.SaveFile(filename.c_str());
return true;
}
示例4: DumpProfilingInfo
static void DumpProfilingInfo()
{
XMLDocument doc;
XMLDeclaration *d = doc.NewDeclaration();
DIVIDEND_EXIT_ERROR_ON(d== NULL, -1, "Invalid XML Declaratio");
doc.InsertEndChild(d);
XMLNode * tnode = doc.NewElement( "DIVIDEND" );
XMLNode * lnode = doc.NewElement( "LWGS" );
DIVIDEND_EXIT_ERROR_ON(tnode == NULL, -1, "Failed to crate a node");
DIVIDEND_EXIT_ERROR_ON(lnode == NULL, -1, "Failed to crate a node");
doc.InsertFirstChild(tnode);
tnode->InsertFirstChild(lnode);
for (unsigned i=0; i<profEventIndex; i++)
{
XMLElement *kElement = doc.NewElement( "Kernel" );
XMLNode * kNode = tnode->InsertFirstChild( kElement );
kElement->SetAttribute("id",KPI[i].kernel_id);
float time = 0.0;
for (unsigned j=0; j<KPI[i].idx; j++)
{
//clGetEventProfilingInfo(KPI[i].event[j], CL_PROFILING_COMMAND_START, sizeof(KPI[i].time_starti[j]), &(KPI[i].time_start[j]), NULL);
//clGetEventProfilingInfo(KPI[i].event[j], CL_PROFILING_COMMAND_END, sizeof(KPI[i].time_end[j]), &(KPI[i].time_end[j]), NULL);
time = time + (KPI[i].time_end[j] - KPI[i].time_start[j])/1000000.0;
}
time = time / (float) KPI[i].idx;
kElement->SetAttribute("time", time);
lnode->InsertEndChild( kElement );
}
tnode->InsertEndChild(lnode);
doc.InsertEndChild(tnode);
doc.SaveFile(DIVIDEND_PROF_FILE_NAME);
}
示例5: main
int main(int argc,char** argv){
XMLDocument doc;
XMLElement* ele = doc.NewElement("mydiv");
doc.NewDeclaration();
ele->SetAttribute("test",10);
doc.InsertEndChild(ele);
if(!doc.SaveFile("test.xml")){
cout<<"success";
};
return 0;
}
示例6: testPrintXML
void testPrintXML() {
XMLDocument doc;
XMLElement* root = doc.NewElement("root");
XMLElement* path = doc.NewElement("status");
XMLText* text = doc.NewText("0");
doc.InsertEndChild(root);
root->InsertEndChild(path);
path->InsertEndChild(text);
XMLPrinter printer(0, true);
doc.Print(&printer);
cout << printer.CStr() << endl;
}
示例7: save
void CSessionParameters::save(std::string _filename){
XMLDocument doc;
char buffer[300], bufferLabel[100];
XMLElement* root = doc.NewElement("configuration");
doc.InsertEndChild(root);
XMLElement* tmpEle = NULL;
for( int idx = 1; idx < MAX_NUM_OF_VIDEOS; ++idx ){
if( filename.count(idx) == 0 || zeroOffset.count(idx) == 0 ){
continue;
}
// filename
sprintf(bufferLabel, "filename%d", idx);
XMLElement* tmpEle = doc.NewElement(bufferLabel);
tmpEle->InsertEndChild( doc.NewText(filename.at(idx).c_str()) );
root->InsertEndChild(tmpEle);
// offset
sprintf(bufferLabel, "offset%d", idx);
tmpEle = doc.NewElement(bufferLabel);
sprintf(buffer, "%d", zeroOffset[idx]);
tmpEle->InsertEndChild( doc.NewText(buffer) );
root->InsertEndChild(tmpEle);
}
// persons
if( pPersons ){
tmpEle = doc.NewElement("persons");
root->InsertEndChild(tmpEle);
for( std::map<int, CPerson*>::iterator iter = pPersons->begin();
iter != pPersons->end(); ++iter )
{
CPerson* tmpPerson = iter->second;
tmpPerson->toXml(&doc, tmpEle);
}
}
// time marks
if( pTimeMarks ){
tmpEle = doc.NewElement("timeline");
root->InsertEndChild(tmpEle);
for( vector<CTimeMark>::iterator iter = pTimeMarks->begin();
iter != pTimeMarks->end(); ++iter)
{
iter->toXml(&doc, tmpEle);
}
}
doc.SaveFile(_filename.c_str());
}
示例8: testErrMsg
void testErrMsg() {
XMLDocument doc;
XMLElement* root;
XMLElement* node;
doc.InsertEndChild(root = doc.NewElement("root"));
root->InsertEndChild(node = doc.NewElement("status"));
node->InsertEndChild(doc.NewText("1"));
root->InsertEndChild(node = doc.NewElement("error"));
node->InsertEndChild(doc.NewText("hello world"));
XMLPrinter printer(0, true);
doc.Print(&printer);
cout << printer.CStr() << endl;
cout << printer.CStrSize() << endl;
cout << strlen(printer.CStr()) << endl;
}
示例9: write
void FileList::write() {
XMLDocument doc;
{
XMLElement* filelist = doc.NewElement("filelist");
filelist->SetAttribute("application", "video-organizer");
filelist->SetAttribute("version", "1.0");
for (unsigned i = 0; i < records.size(); i++) {
XMLElement* record = doc.NewElement("record");
record->SetAttribute("from", records[i].from.c_str());
record->SetAttribute("to", records[i].to.c_str());
record->SetAttribute("action", records[i].action);
filelist->InsertEndChild(record);
}
doc.InsertEndChild(filelist);
}
XMLError ret = doc.SaveFile((dir + "filelist").c_str());
if (ret) console.e("Error writing filelist: %s", ret);
}
示例10: writeToFile
void CSettings::writeToFile() {
XMLDocument doc;
XMLElement *pSettingsElem = doc.NewElement("settings");
doc.InsertEndChild(pSettingsElem);
// Input
XMLElement *pInput = doc.NewElement("input");
pSettingsElem->InsertEndChild(pInput);
pInput->SetAttribute("map_editor_button_size",
m_InputSettings.m_fMapEditorButtonSize);
XMLElement *pInputTouch = doc.NewElement("touch");
pInput->InsertEndChild(pInputTouch);
pInputTouch->SetAttribute("button_size", m_InputSettings.m_fTouchButtonSize);
// video
XMLElement *pVideo = doc.NewElement("video");
pSettingsElem->InsertEndChild(pVideo);
pVideo->SetAttribute("hud_size", m_VideoSettings.m_fHUDSize);
// social gaming
XMLElement *pSocialGaming = doc.NewElement("social_gaming");
pSettingsElem->InsertEndChild(pSocialGaming);
pSocialGaming->SetAttribute("login_on_start", m_SocialGamingSettings.m_bLoginOnStart ? "true" : "false");
// do the output
XMLPrinter xmlprinter;
doc.Accept(&xmlprinter);
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
std::string text(xmlprinter.CStr());
std::fstream stream;
if (CFileManager::openFile(stream, SETTINGS_FILE_PATH, std::ofstream::out | std::ofstream::trunc)) {
stream << header;
stream << text;
stream.close();
}
}
示例11: main
//.........这里部分代码省略.........
"<element><b></b></element>",
"<element>Text inside and <b>bolded</b> in the element.</element>",
"<outer><element>Text inside and <b>bolded</b> in the element.</element></outer>",
"<element>This & That.</element>",
"<element attrib='This<That' />",
0
};
for( int i=0; test[i]; ++i ) {
XMLDocument doc;
doc.Parse( test[i] );
doc.Print();
printf( "----------------------------------------------\n" );
}
}
#if 1
{
static const char* test = "<!--hello world\n"
" line 2\r"
" line 3\r\n"
" line 4\n\r"
" line 5\r-->";
XMLDocument doc;
doc.Parse( test );
doc.Print();
}
{
static const char* test = "<element>Text before.</element>";
XMLDocument doc;
doc.Parse( test );
XMLElement* root = doc.FirstChildElement();
XMLElement* newElement = doc.NewElement( "Subelement" );
root->InsertEndChild( newElement );
doc.Print();
}
{
XMLDocument* doc = new XMLDocument();
static const char* test = "<element><sub/></element>";
doc->Parse( test );
delete doc;
}
{
// Test: Programmatic DOM
// Build:
// <element>
// <!--comment-->
// <sub attrib="1" />
// <sub attrib="2" />
// <sub attrib="3" >& Text!</sub>
// <element>
XMLDocument* doc = new XMLDocument();
XMLNode* element = doc->InsertEndChild( doc->NewElement( "element" ) );
XMLElement* sub[3] = { doc->NewElement( "sub" ), doc->NewElement( "sub" ), doc->NewElement( "sub" ) };
for( int i=0; i<3; ++i ) {
sub[i]->SetAttribute( "attrib", i );
}
element->InsertEndChild( sub[2] );
XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
element->InsertAfterChild( comment, sub[0] );
element->InsertAfterChild( sub[0], sub[1] );
sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
doc->Print();
XMLTest( "Programmatic DOM", "comment", doc->FirstChildElement( "element" )->FirstChild()->Value() );
示例12: main
int main( int /*argc*/, const char ** /*argv*/ )
{
#if defined( _MSC_VER ) && defined( DEBUG )
_CrtMemCheckpoint( &startMemState );
#endif
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable : 4996 ) // Fail to see a compelling reason why this should be deprecated.
#endif
FILE* fp = fopen( "dream.xml", "r" );
if ( !fp ) {
printf( "Error opening test file 'dream.xml'.\n"
"Is your working directory the same as where \n"
"the xmltest.cpp and dream.xml file are?\n\n"
#if defined( _MSC_VER )
"In windows Visual Studio you may need to set\n"
"Properties->Debugging->Working Directory to '..'\n"
#endif
);
exit( 1 );
}
fclose( fp );
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
/* ------ Example 1: Load and parse an XML file. ---- */
{
XMLDocument doc;
doc.LoadFile( "dream.xml" );
}
/* ------ Example 2: Lookup information. ---- */
{
XMLDocument doc;
doc.LoadFile( "dream.xml" );
// Structure of the XML file:
// - Element "PLAY" the root Element
// - - Element "TITLE" child of the root PLAY Element
// - - - Text child of the TITLE Element
// Navigate to the title, using the convenience function, with a dangerous lack of error checking.
const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText();
printf( "Name of play (1): %s\n", title );
// Text is just another Node to TinyXML-2. The more general way to get to the XMLText:
XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText();
title = textNode->Value();
printf( "Name of play (2): %s\n", title );
}
{
static const char* test[] = { "<element />",
"<element></element>",
"<element><subelement/></element>",
"<element><subelement></subelement></element>",
"<element><subelement><subsub/></subelement></element>",
"<!--comment beside elements--><element><subelement></subelement></element>",
"<!--comment beside elements, this time with spaces--> \n <element> <subelement> \n </subelement> </element>",
"<element attrib1='foo' attrib2=\"bar\" ></element>",
"<element attrib1='foo' attrib2=\"bar\" ><subelement attrib3='yeehaa' /></element>",
"<element>Text inside element.</element>",
"<element><b></b></element>",
"<element>Text inside and <b>bolded</b> in the element.</element>",
"<outer><element>Text inside and <b>bolded</b> in the element.</element></outer>",
"<element>This & That.</element>",
"<element attrib='This<That' />",
0
};
for( int i=0; test[i]; ++i ) {
XMLDocument doc;
doc.Parse( test[i] );
doc.Print();
printf( "----------------------------------------------\n" );
}
}
#if 1
{
static const char* test = "<!--hello world\n"
" line 2\r"
" line 3\r\n"
" line 4\n\r"
" line 5\r-->";
XMLDocument doc;
doc.Parse( test );
doc.Print();
}
{
static const char* test = "<element>Text before.</element>";
XMLDocument doc;
doc.Parse( test );
XMLElement* root = doc.FirstChildElement();
XMLElement* newElement = doc.NewElement( "Subelement" );
root->InsertEndChild( newElement );
//.........这里部分代码省略.........
示例13: dumpSearchResult
bool DividendTuningOptFileRoutines::dumpSearchResult(const std::vector<DividendLWSKernelConf> confs, string& fname)
{
fname = DIVIDEND_LWS_TUNING_RESULT_PREFIX;
time_t rawtime;
struct tm *info;
char buffer[80];
time( &rawtime );
info = localtime( &rawtime );
strftime(buffer,80,"-%Y%m%dT%H%M%S%z", info);
fname = fname + buffer;
fname = fname + ".xml";
XMLDocument doc;
doc.InsertEndChild (doc.NewDeclaration() );
XMLNode *tnode = doc.NewElement( "DIVIDEND" );
XMLNode *lnode = doc.NewElement( "LWGS" );
XMLNode *kkNode = NULL;
for (unsigned i=0; i<confs.size(); i++)
{
const DividendLWSKernelConf& c = confs[i];
XMLElement * knode = doc.NewElement( "kernel" );
knode->SetAttribute("id", c.kernel_id);
knode->SetAttribute("dim", c.best.dim);
knode->SetAttribute("rsize", (unsigned int)c.confs.size());
XMLNode *pcNode = NULL;
for (unsigned j=0; j<c.confs.size(); j++)
{
const DividendLWSConf& CC = c.confs[j];
XMLElement * ccnode = doc.NewElement( "config" );
ccnode->SetAttribute("id", j);
ccnode->SetAttribute("runtime", (double)CC.time);
ccnode->SetAttribute("speedup", CC.defaultT / CC.time);
ccnode->SetAttribute("ci", CC.ci);
if (pcNode)
{
knode->InsertAfterChild(pcNode, ccnode);
}
else
{
knode->InsertFirstChild(ccnode);
}
pcNode = ccnode;
XMLElement *ppNode = NULL;
for (unsigned k=0; k<CC.dim; k++)
{
XMLElement *mnode = doc.NewElement ("paramter");
mnode->SetAttribute("macroname", CC.macroName[k].c_str());
mnode->SetAttribute("val", CC.val[k]);
if (ppNode)
{
ccnode->InsertAfterChild(ppNode, mnode);
}
else
{
ccnode->InsertFirstChild(mnode);
}
ppNode = mnode;
}
}
if (kkNode)
{
lnode->InsertAfterChild(kkNode, knode);
}
else
{
lnode->InsertFirstChild(knode);
}
kkNode = knode;
}
tnode->InsertEndChild(lnode);
doc.InsertEndChild(tnode);
return doc.SaveFile(fname.c_str()) == XML_NO_ERROR;
}
示例14: load
void AtanuaConfig::load()
{
XMLDocument doc;
XMLDeclaration *pDec;
XMLElement *pRoot;
XMLElement *pElement;
FILE * f = fopen("atanua.xml", "rb");
if (!f)
{
// Save config
pDec = doc.NewDeclaration();
doc.InsertEndChild(pDec);
pRoot = doc.NewElement("AtanuaConfig");
pRoot->SetAttribute("GeneratedWith",TITLE);
doc.InsertEndChild(pRoot);
pElement = doc.NewElement("PropagateInvalidState");
pElement->SetAttribute("value", mPropagateInvalidState == PINSTATE_PROPAGATE_INVALID);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("CustomCursors");
pElement->SetAttribute("value", mCustomCursors);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("PerformanceIndicators");
pElement->SetAttribute("value", mPerformanceIndicators);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("SwapShiftAndCtrl");
pElement->SetAttribute("value", mSwapShiftAndCtrl);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("WireFry");
pElement->SetAttribute("value", mWireFry);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("AudioEnable");
pElement->SetAttribute("value", mAudioEnable);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("ToolkitWidth");
pElement->SetAttribute("value", mToolkitWidth);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("MaxPhysicsMs");
pElement->SetAttribute("value", mMaxPhysicsMs);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("InitialWindow");
pElement->SetAttribute("width", mWindowWidth);
pElement->SetAttribute("height", mWindowHeight);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("TooltipDelay");
pElement->SetAttribute("value", mTooltipDelay);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("LinePickTolerance");
pElement->SetAttribute("value", mLinePickTolerance);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("LineEndTolerance");
pElement->SetAttribute("value", mLineEndTolerance);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("LineSplitDragDistance");
pElement->SetAttribute("value", mLineSplitDragDistance);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("ChipCloneDragDistance");
pElement->SetAttribute("value", mChipCloneDragDistance);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("User");
pElement->SetAttribute("name", "[No user name set]");
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("FontSystem");
pElement->SetAttribute("CacheKeys", mFontCacheMax);
pElement->SetAttribute("VBO", mUseVBOs);
pElement->SetAttribute("SafeMode", mUseOldFontSystem);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("PerformanceOptions");
pElement->SetAttribute("Blending", mUseBlending);
pElement->SetAttribute("AntialiasedLines", mAntialiasedLines);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("Limits");
pElement->SetAttribute("MaxBoxes", mMaxActiveBoxes);
pElement->SetAttribute("PhysicsKHz", mPhysicsKHz);
pRoot->InsertEndChild(pElement);
pElement = doc.NewElement("LED");
pElement->SetAttribute("Samples", mLEDSamples);
pRoot->InsertEndChild(pElement);
//.........这里部分代码省略.........
示例15: save
bool FractalConfiguration::save(string filename)
{
if(invalidID())
return true;
// Check filename and append .xml
if(!endsWith(filename, ".xml"))
filename += ".xml";
// Create document
XMLDocument doc;
// Root element
XMLElement *root = doc.NewElement("fractal");
root->SetAttribute("id", m_id.c_str());
doc.InsertEndChild(root);
// Add properties
iterate();
while(true)
{
if(!next())
break;
XMLElement *prop = doc.NewElement("property");
prop->SetAttribute("name", getName().c_str());
XMLText *text = doc.NewText("");
if(isString())
{
prop->SetAttribute("type", "string");
text->SetValue(getString().c_str());
}
else if(isInt())
{
prop->SetAttribute("type", "int");
stringstream ss;
ss << getInt();
text->SetValue(ss.str().c_str());
}
else if(isDouble())
{
prop->SetAttribute("type", "double");
stringstream ss;
ss << getDouble();
text->SetValue(ss.str().c_str());
}
else if(isBool())
{
prop->SetAttribute("type", "bool");
if(getBool())
text->SetValue("1");
else
text->SetValue("0");
}
prop->InsertEndChild(text);
root->InsertEndChild(prop);
}
// Save to file
if(doc.SaveFile(filename.c_str()) != XML_NO_ERROR)
{
m_last_error = doc.GetErrorStr1();
return true;
}
resetDirty();
return false;
}