本文整理汇总了C++中XmlWriter::addBody方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlWriter::addBody方法的具体用法?C++ XmlWriter::addBody怎么用?C++ XmlWriter::addBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlWriter
的用法示例。
在下文中一共展示了XmlWriter::addBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StoreResult
//////////////////////////////////////////////////////////////
///Stores results of analysis into a text file
void FileSniffer::StoreResult()
{
try{
std::stringstream ss;
ss<<newfilesList.size();
XmlWriter writer; //create new xml
writer.addDeclaration();
writer.start("filelist");
XmlWriter childnode1;
childnode1.start("listsize"); //add filepath tag for each path
childnode1.addBody(ss.str()); //add path
childnode1.end(); //add ending tag
writer.addBody(childnode1.xml());
for (std::set<std::string>::iterator it=newfilesList.begin(); it != newfilesList.end(); it++) //add all paths in fileset to the xml
{
XmlWriter childnode;
childnode.start("filepath"); //add filepath tag for each path
childnode.addBody(*it); //add path
childnode.end(); //add ending tag
writer.addBody(childnode.xml());
}
writer.end();
std::ofstream myfile; //create new file and write the xml in it
myfile.open (resultFilePath.c_str());
myfile << writer.xml();
myfile.close();
}
catch(std::exception ex)
{
std::cout << "\n " << ex.what() << "\n\n";
}
}
示例2: createDatabase
//////////////////////////////////////////////////////////////////////////////////////////
///Creates the XML database file from a set of filepaths and returns number of new paths
int FileSniffer::createDatabase(std::set<std::string>& filelist)
{
int count=0;
try{
XmlWriter writer; //create new xml
writer.addDeclaration();
writer.start("filelist");
newfilesList.clear();
for (std::set<std::string>::iterator it=filelist.begin(); it != filelist.end(); it++) //add all paths in fileset to the xml
{
if(!isInExcluded(*it))
{
count++;
XmlWriter childnode;
childnode.start("filepath"); //add filepath tag for each path
childnode.addBody(*it); //add path
childnode.end(); //add ending tag
writer.addBody(childnode.xml());
newfilesList.insert(*it);
}
}
writer.end();
std::ofstream myfile; //create new file and write the xml in it
myfile.open (databaseFilePath.c_str());
myfile << writer.xml();
myfile.close();
StoreResult();
}
catch(std::exception ex)
{
std::cout << "\n " << ex.what() << "\n\n";
}
return count;
}
示例3: main
void main()
{
//mOut("Testing XmlWriter");
//mOut("=================");
//mOut("creating XML writer object:");
XmlWriter wtr;
//mOut("adding XML declaration:");
wtr.addDeclaration();
//mOut(wtr.xml());
//mOut("adding comment:");
wtr.addComment("top level comment");
//mOut(wtr.xml());
//mOut("adding root element:");
wtr.start("root");
//mOut(wtr.xml());
//mOut("adding attributes:");
wtr.addAttribute("att1","val1");
wtr.addAttribute("att2","val2");
//mOut(wtr.xml());
//mOut("adding comment:");
wtr.addComment("comment in root's body");
//mOut(wtr.xml());
//mOut("Creating self-closing element:");
XmlWriter sub1;
sub1.start("child1 /");
// mOut(sub1.xml());
//mOut("adding attribute:");
sub1.addAttribute("c1name","c1value");
XmlWriter subsub1;
subsub1.start("grand");
subsub1.addBody("test grandchild");
subsub1.end();
sub1.addBody(subsub1.xml());
//mOut(sub1.xml());
//mOut("adding child to root's body:");
wtr.addBody(sub1.xml());
//mOut(wtr.xml());
//mOut("adding another comment");
wtr.addComment("another root's body comment");
//mOut(wtr.xml());
//mOut("adding string to root's body:");
wtr.addBody("root's body");
//mOut(wtr.xml());
//mOut("closing root element:\n");
wtr.end();
mOut(wtr.xml());
mOut("\n writing XML to file \"Test.xml\":");
std::ofstream out("test.xml");
if(out.good())
{
out << wtr.xml().c_str();
out.close();
}
std::cout << std::endl;
/* mOut("creating composite element:");
XmlWriter cwtr, bcwtr1, bcwtr2;
std::string temp =
bcwtr1.element("child1","child1's body")
.element("child2","child2's body").xml();
std::cout << "\n " << bcwtr1.xml();
bcwtr1.clear();
std::cout << "\n " <<
cwtr.start("parent")
.addBody(bcwtr1.element("child1","child1's body").xml())
.addBody(bcwtr2.element("child2","body2").xml())
.end().xml();
std::cout << "\n\n";*/
}