本文整理汇总了C++中TiXmlNode::Print方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlNode::Print方法的具体用法?C++ TiXmlNode::Print怎么用?C++ TiXmlNode::Print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlNode
的用法示例。
在下文中一共展示了TiXmlNode::Print方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFromXML
/**
* 从xml文件中读取“键-值”对 load "key-value" from xml file
* @param filename 读取的xml文件,必须是按照规定的格式
* @return 布尔值 读取成功与否
*/
bool Properties::loadFromXML(const string filename)
{
TiXmlDocument doc(filename.c_str());
bool loadOkay = doc.LoadFile();//以utf-8格式读取xml文件
if (!loadOkay)
{
return false;
}
TiXmlNode *node = doc.FirstChild("properties");
#ifdef DEBUG_PROPERTIES_H
node->Print(stdout, 1);
cout << endl;
#endif
TiXmlElement* propertiesElement = node->ToElement();
for(TiXmlElement *it = propertiesElement->FirstChildElement("entry")
; it!=NULL ;
it = it->NextSiblingElement("entry")
)
{
TiXmlAttribute *att = it->FirstAttribute();
this->setProperty(att->Value(), it->GetText());
#ifdef DEBUG_PROPERTIES_H
cout << "[" << att->Name() << ":" << att->Value() << "->" << it->GetText() << "]" << endl;
#endif
}
return true;
}
示例2: Print
void TiXmlElement::Print(FILE* cfile, int depth) const
{
int i;
assert(cfile);
for (i = 0; i < depth; i++)
{
fprintf(cfile, " ");
}
fprintf(cfile, "<%s", value.c_str());
const TiXmlAttribute* attrib;
for (attrib = attributeSet.First(); attrib; attrib = attrib->Next())
{
fprintf(cfile, " ");
attrib->Print(cfile, depth);
}
// There are 3 different formatting approaches:
// 1) An element without children is printed as a <foo /> node
// 2) An element with only a text child is printed as <foo> text </foo>
// 3) An element with children is printed on multiple lines.
TiXmlNode* node;
if (!firstChild)
{
fprintf(cfile, " />");
}
else if (firstChild == lastChild && firstChild->ToText())
{
fprintf(cfile, ">");
firstChild->Print(cfile, depth + 1);
fprintf(cfile, "</%s>", value.c_str());
}
else
{
fprintf(cfile, ">");
for (node = firstChild; node; node = node->NextSibling())
{
if (!node->ToText())
{
fprintf(cfile, "\n");
}
node->Print(cfile, depth + 1);
}
fprintf(cfile, "\n");
for (i = 0; i < depth; ++i)
{
fprintf(cfile, " ");
}
fprintf(cfile, "</%s>", value.c_str());
}
}
示例3: Print
void TiXmlDocument::Print( FILE* cfile, int depth ) const
{
TiXmlNode* node;
for ( node=FirstChild(); node; node=node->NextSibling() )
{
node->Print( cfile, depth );
generic_fprintf( cfile, TEXT("\n") );
}
}
示例4: Print
void TiXmlDocument::Print( FILE* fp, int )
{
TiXmlNode* node;
for ( node=FirstChild(); node; node=node->NextSibling() )
{
node->Print( fp, 0 );
fprintf( fp, "\n" );
}
}
示例5: Print
void TiXmlElement::Print( FileOps *f, int depth ) const
{
const char *newLine = "\n";
const char *tabSpacer = " ";
const char *startTag = "<";
const char *startEndTag = "</";
const char *closeEmptyElement = " />";
const char *closeTag = ">";
const char *singleSpace = " ";
int i;
assert( f );
for ( i=0; i<depth; i++ ) {
f->write(tabSpacer, 3, 1);
}
f->write(startTag, 1, 1);
f->write(value.c_str(), value.size(), 1);
const TiXmlAttribute* attrib;
for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
{
f->write(singleSpace, 1, 1);
attrib->Print( f, depth );
}
// There are 3 different formatting approaches:
// 1) An element without children is printed as a <foo /> node
// 2) An element with only a text child is printed as <foo> text </foo>
// 3) An element with children is printed on multiple lines.
TiXmlNode* node;
if ( !firstChild )
{
f->write(closeEmptyElement, 3, 1);
}
else if ( firstChild == lastChild && firstChild->ToText() )
{
f->write(closeTag, 1, 1);
firstChild->Print( f, depth + 1 );
f->write(startEndTag, 2, 1);
f->write(value.c_str(), value.size(), 1);
f->write(closeTag, 1, 1);
}
else
{
f->write(closeTag, 1, 1);
for ( node = firstChild; node; node=node->NextSibling() )
{
if ( !node->ToText() )
{
f->write(newLine, strlen(newLine), 1);
}
node->Print( f, depth+1 );
}
f->write(newLine, strlen(newLine), 1);
for( i=0; i<depth; ++i ) {
f->write(tabSpacer, 3, 1);
}
f->write(startEndTag, 2, 1);
f->write(value.c_str(), value.size(), 1);
f->write(closeTag, 1, 1);
}
}