本文整理汇总了C++中TiXmlDeclaration类的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlDeclaration类的具体用法?C++ TiXmlDeclaration怎么用?C++ TiXmlDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TiXmlDeclaration类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClearError
const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding )
{
ClearError();
// Parse away, at the document level. Since a document
// contains nothing but other tags, most of what happens
// here is skipping white space.
if ( !p || !*p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// Note that, for a document, this needs to come
// before the while space skip, so that parsing
// starts from the pointer we are given.
location.Clear();
if ( prevData )
{
location.row = prevData->cursor.row;
location.col = prevData->cursor.col;
}
else
{
location.row = 0;
location.col = 0;
}
TiXmlParsingData data( p, TabSize(), location.row, location.col );
location = data.Cursor();
if ( encoding == TIXML_ENCODING_UNKNOWN )
{
// Check for the Microsoft UTF-8 lead bytes.
if ( *(p+0) && *(p+0) == (char)(0xef)
&& *(p+1) && *(p+1) == (char)(0xbb)
&& *(p+2) && *(p+2) == (char)(0xbf) )
{
encoding = TIXML_ENCODING_UTF8;
}
}
p = SkipWhiteSpace( p, encoding );
if ( !p )
{
SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
while ( p && *p )
{
TiXmlNode* node = Identify( p, encoding );
if ( node )
{
p = node->Parse( p, &data, encoding );
LinkEndChild( node );
}
else
{
break;
}
// Did we get encoding info?
if ( encoding == TIXML_ENCODING_UNKNOWN
&& node->ToDeclaration() )
{
TiXmlDeclaration* dec = node->ToDeclaration();
const char* enc = dec->Encoding();
assert( enc );
if ( *enc == 0 )
encoding = TIXML_ENCODING_UTF8;
else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
encoding = TIXML_ENCODING_UTF8;
else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
else
encoding = TIXML_ENCODING_LEGACY;
}
p = SkipWhiteSpace( p, encoding );
}
// All is well.
return p;
}
示例2: TiXmlNode
TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy )
: TiXmlNode( TiXmlNode::DECLARATION )
{
copy.CopyTo( this );
}
示例3: Clear
void TiXmlDeclaration::operator=( const TiXmlDeclaration& copy )
{
Clear();
copy.CopyTo( this );
}
示例4: main
//.........这里部分代码省略.........
TiXmlAttribute* doors = room->FirstAttribute();
assert(doors);
XmlTest("Location tracking: Tab 8: room row", room->Row(), 1);
XmlTest("Location tracking: Tab 8: room col", room->Column(), 49);
XmlTest("Location tracking: Tab 8: doors row", doors->Row(), 1);
XmlTest("Location tracking: Tab 8: doors col", doors->Column(), 55);
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
" <!-- Silly example -->\n"
" <door wall='north'>A great door!</door>\n"
"\t<door wall='east'/>"
"</room>";
TiXmlDocument doc;
doc.Parse(str);
TiXmlHandle docHandle(&doc);
TiXmlHandle roomHandle = docHandle.FirstChildElement("room");
TiXmlHandle commentHandle = docHandle.FirstChildElement("room").FirstChild();
TiXmlHandle textHandle = docHandle.FirstChildElement("room").ChildElement("door", 0).FirstChild();
TiXmlHandle door0Handle = docHandle.FirstChildElement("room").ChildElement(0);
TiXmlHandle door1Handle = docHandle.FirstChildElement("room").ChildElement(1);
assert(docHandle.Node());
assert(roomHandle.Element());
assert(commentHandle.Node());
assert(textHandle.Text());
assert(door0Handle.Element());
assert(door1Handle.Element());
TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration();
assert(declaration);
TiXmlElement* room = roomHandle.Element();
assert(room);
TiXmlAttribute* doors = room->FirstAttribute();
assert(doors);
TiXmlText* text = textHandle.Text();
TiXmlComment* comment = commentHandle.Node()->ToComment();
assert(comment);
TiXmlElement* door0 = door0Handle.Element();
TiXmlElement* door1 = door1Handle.Element();
XmlTest("Location tracking: Declaration row", declaration->Row(), 1);
XmlTest("Location tracking: Declaration col", declaration->Column(), 5);
XmlTest("Location tracking: room row", room->Row(), 1);
XmlTest("Location tracking: room col", room->Column(), 45);
XmlTest("Location tracking: doors row", doors->Row(), 1);
XmlTest("Location tracking: doors col", doors->Column(), 51);
XmlTest("Location tracking: Comment row", comment->Row(), 2);
XmlTest("Location tracking: Comment col", comment->Column(), 3);
XmlTest("Location tracking: text row", text->Row(), 3);
XmlTest("Location tracking: text col", text->Column(), 24);
XmlTest("Location tracking: door0 row", door0->Row(), 3);
XmlTest("Location tracking: door0 col", door0->Column(), 5);
XmlTest("Location tracking: door1 row", door1->Row(), 4);
XmlTest("Location tracking: door1 col", door1->Column(), 5);
}
// --------------------------------------------------------
// UTF-8 testing. It is important to test:
// 1. Making sure name, value, and text read correctly
// 2. Row, Col functionality
示例5: 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;
}
}
}
示例6: main
//.........这里部分代码省略.........
" <wrong error>\n"
"</passages>";
TiXmlDocument doc;
doc.Parse( error );
XmlTest( "Error row", doc.ErrorRow(), 3 );
XmlTest( "Error column", doc.ErrorCol(), 17 );
//printf( "error=%d id='%s' row %d col%d\n", (int) doc.Error(), doc.ErrorDesc(), doc.ErrorRow()+1, doc.ErrorCol() + 1 );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
" <!-- Silly example -->\n"
" <door wall='north'>A great door!</door>\n"
"\t<door wall='east'/>"
"</room>";
TiXmlDocument doc;
doc.Parse( str );
TiXmlHandle docHandle( &doc );
TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
TiXmlHandle commentHandle = docHandle.FirstChildElement( "room" ).FirstChild();
TiXmlHandle textHandle = docHandle.FirstChildElement( "room" ).ChildElement( "door", 0 ).FirstChild();
TiXmlHandle door0Handle = docHandle.FirstChildElement( "room" ).ChildElement( 0 );
TiXmlHandle door1Handle = docHandle.FirstChildElement( "room" ).ChildElement( 1 );
assert( docHandle.Node() );
assert( roomHandle.Element() );
assert( commentHandle.Node() );
assert( textHandle.Text() );
assert( door0Handle.Element() );
assert( door1Handle.Element() );
TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration();
assert( declaration );
TiXmlElement* room = roomHandle.Element();
assert( room );
TiXmlAttribute* doors = room->FirstAttribute();
assert( doors );
TiXmlText* text = textHandle.Text();
TiXmlComment* comment = commentHandle.Node()->ToComment();
assert( comment );
TiXmlElement* door0 = door0Handle.Element();
TiXmlElement* door1 = door1Handle.Element();
XmlTest( "Location tracking: Declaration row", declaration->Row(), 1 );
XmlTest( "Location tracking: Declaration col", declaration->Column(), 5 );
XmlTest( "Location tracking: room row", room->Row(), 1 );
XmlTest( "Location tracking: room col", room->Column(), 45 );
XmlTest( "Location tracking: doors row", doors->Row(), 1 );
XmlTest( "Location tracking: doors col", doors->Column(), 51 );
XmlTest( "Location tracking: Comment row", comment->Row(), 2 );
XmlTest( "Location tracking: Comment col", comment->Column(), 3 );
XmlTest( "Location tracking: text row", text->Row(), 3 );
XmlTest( "Location tracking: text col", text->Column(), 24 );
XmlTest( "Location tracking: door0 row", door0->Row(), 3 );
XmlTest( "Location tracking: door0 col", door0->Column(), 5 );
XmlTest( "Location tracking: door1 row", door1->Row(), 4 );
XmlTest( "Location tracking: door1 col", door1->Column(), 5 );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
"</room>";
TiXmlDocument doc;
doc.SetTabSize( 8 );
示例7: defined
void ProjectFileWriter::ConvertANSIXMLFile(TiXmlHandle & hdl, TiXmlDocument & doc, const gd::String & filename)
{
//COMPATIBILITY CODE WITH ANSI GDEVELOP ( <= 3.6.83 )
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) //There should not be any problem with encoding in compiled games
//Get the declaration element
TiXmlDeclaration * declXmlElement = hdl.FirstChild().ToNode()->ToDeclaration();
if(strcmp(declXmlElement->Encoding(), "UTF-8") != 0)
{
std::cout << "This is a legacy GDevelop project, checking if it is already encoded in UTF8..." << std::endl;
//The document has not been converted for/saved by GDevelop UTF8, now, try to determine if the project
//was saved on Linux and is already in UTF8 or on Windows and still in the locale encoding.
bool isNotInUTF8 = false;
std::ifstream docStream;
docStream.open(filename.ToLocale(), std::ios::in);
while( !docStream.eof() )
{
std::string docLine;
std::getline(docStream, docLine);
if( !gd::String::FromUTF8(docLine).IsValid() )
{
//The file contains an invalid character,
//the file has been saved by the legacy ANSI Windows version of GDevelop
// -> stop reading the file and start converting from the locale to UTF8
isNotInUTF8 = true;
break;
}
}
docStream.close();
//If the file is not encoded in UTF8, encode it
if(isNotInUTF8)
{
std::cout << "The project file is not encoded in UTF8, conversion started... ";
//Create a temporary file
#if defined(WINDOWS)
//Convert using the current locale
wxString tmpFileName = wxFileName::CreateTempFileName("");
std::ofstream outStream;
docStream.open(filename.ToLocale(), std::ios::in);
outStream.open(tmpFileName, std::ios::out | std::ios::trunc);
while( !docStream.eof() )
{
std::string docLine;
std::string convLine;
std::getline(docStream, docLine);
sf::Utf8::fromAnsi(docLine.begin(), docLine.end(), std::back_inserter(convLine));
outStream << convLine << '\n';
}
outStream.close();
docStream.close();
#else
//Convert using iconv command tool
wxString tmpFileName = wxStandardPaths::Get().GetUserConfigDir() + "/gdevelop_converted_project";
gd::String iconvCall = gd::String("iconv -f LATIN1 -t UTF-8 \"") + filename.ToLocale() + "\" ";
#if defined(MACOS)
iconvCall += "> \"" + tmpFileName + "\"";
#else
iconvCall += "-o \"" + tmpFileName + "\"";
#endif
std::cout << "Executing " << iconvCall << std::endl;
system(iconvCall.c_str());
#endif
//Reload the converted file, forcing UTF8 encoding as the XML header is false (still written ISO-8859-1)
doc.LoadFile(std::string(tmpFileName).c_str(), TIXML_ENCODING_UTF8);
std::cout << "Finished." << std::endl;
gd::LogMessage(_("Your project has been upgraded to be used with GDevelop 4.\nIf you save it, you won't be able to open it with an older version: please do a backup of your project file if you want to go back to GDevelop 3."));
}
}
#endif
//END OF COMPATIBILITY CODE
}