本文整理汇总了C++中TiXmlDeclaration::Standalone方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlDeclaration::Standalone方法的具体用法?C++ TiXmlDeclaration::Standalone怎么用?C++ TiXmlDeclaration::Standalone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlDeclaration
的用法示例。
在下文中一共展示了TiXmlDeclaration::Standalone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readSchoolXml
void readSchoolXml()
{
using namespace std;
const char *xmlFile = "conf/school.xml";
TiXmlDocument doc;
if (!doc.LoadFile(xmlFile))
{
cout << "Load xml file failed.\t" << xmlFile << endl;
return;
}
cout << "Load xml file OK." << endl;
TiXmlDeclaration *decl = doc.FirstChild()->ToDeclaration();
if (!decl)
{
cout << "decl is null.\n" << endl;
return;
}
cout << decl->Encoding();
cout << decl->Version();
cout << decl->Standalone() << endl;
TiXmlHandle docHandle(&doc);
TiXmlElement *child
= docHandle.FirstChild("School").FirstChild("Class").Child("Student", 0).ToElement();
for ( ; child != NULL; child = child->NextSiblingElement())
{
TiXmlAttribute *attr = child->FirstAttribute();
for (; attr != NULL; attr = attr->Next())
{
cout << attr->Name() << " : " << attr->Value() << endl;
}
TiXmlElement *ct = child->FirstChildElement();
for (; ct != NULL; ct = ct->NextSiblingElement())
{
char buf[1024] = {0};
u2g(ct->GetText(), strlen(ct->GetText()), buf, sizeof(buf));
cout << ct->Value() << " : " << buf << endl;
}
cout << "=====================================" << endl;
}
TiXmlElement *schl = doc.RootElement();
const char *value_t =schl->Attribute("name");
char buf[1024] = {0};
if ( u2g(value_t, strlen(value_t), buf, sizeof(buf)) == -1) {
return;
}
cout << "Root Element value: " << buf << endl;
schl->RemoveAttribute("name");
schl->SetValue("NewSchool");
cout << "Save file: " << (doc.SaveFile("conf/new.xml") ? "Ok" : "Failed") << endl;
return ;
TiXmlElement *rootElement = doc.RootElement();
TiXmlElement *classElement = rootElement->FirstChildElement();
TiXmlElement *studentElement = classElement->FirstChildElement();
// N 个 Student 节点
for ( ; studentElement!= NULL; studentElement = studentElement->NextSiblingElement())
{
// 获得student
TiXmlAttribute *stuAttribute = studentElement->FirstAttribute();
for (; stuAttribute != NULL; stuAttribute = stuAttribute->Next())
{
cout << stuAttribute->Name() << " : " << stuAttribute->Value() << endl;
}
// 获得student的第一个联系方式
TiXmlElement *contact = studentElement->FirstChildElement();
for (; contact != NULL; contact = contact->NextSiblingElement())
{
const char *text = contact->GetText();
char buf[1024] = {0};
if ( u2g(text, strlen(text), buf, sizeof(buf)) == -1) {
continue;
}
cout << contact->Value() << " : " << buf << endl;
}
}
}