当前位置: 首页>>代码示例>>C++>>正文


C++ TiXmlDeclaration::Encoding方法代码示例

本文整理汇总了C++中TiXmlDeclaration::Encoding方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlDeclaration::Encoding方法的具体用法?C++ TiXmlDeclaration::Encoding怎么用?C++ TiXmlDeclaration::Encoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TiXmlDeclaration的用法示例。


在下文中一共展示了TiXmlDeclaration::Encoding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Parse

bool CRssReader::Parse(LPSTR szBuffer, int iFeed)
{
  m_xml.Clear();
  m_xml.Parse((LPCSTR)szBuffer, 0, TIXML_ENCODING_LEGACY);

  if (m_iconv != (iconv_t) -1)
  {
    iconv_close(m_iconv);
      m_iconv = (iconv_t) -1;
    m_shouldFlip = false;
  }

  m_encoding = "UTF-8";
  if (m_xml.RootElement())
  {
    TiXmlDeclaration *tiXmlDeclaration = m_xml.RootElement()->Parent()->FirstChild()->ToDeclaration();
    if (tiXmlDeclaration != NULL && strlen(tiXmlDeclaration->Encoding()) > 0)
    {
      m_encoding = tiXmlDeclaration->Encoding();
    }
  }

  CLog::Log(LOGDEBUG, "RSS feed encoding: %s", m_encoding.c_str());
  
  m_iconv = iconv_open(WCHAR_CHARSET, m_encoding.c_str());

  if (g_charsetConverter.isBidiCharset(m_encoding))
  {
    m_shouldFlip = true;
  }

  return Parse(iFeed);
}
开发者ID:jimmyswimmy,项目名称:plex,代码行数:33,代码来源:RssReader.cpp

示例2: Parse

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.
		const unsigned char* pU = (const unsigned char*)p;
		if (	*(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
			 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
			 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
		{
			encoding = TIXML_ENCODING_UTF8;
			useMicrosoftBOM = true;
		}
	}

    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 );
	}

	// Was this empty?
	if ( !firstChild ) {
		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
		return 0;
	}

	// All is well.
	return p;
}
开发者ID:fangbaolei,项目名称:EC700IR,代码行数:93,代码来源:tinyxmlparser.cpp

示例3: main


//.........这里部分代码省略.........
		XmlTest( "Copy/Assign: element assign #2.", "value", elementAssign.Attribute( "name" ) );
		XmlTest( "Copy/Assign: element assign #3.", true, ( 0 == elementAssign.Attribute( "foo" )) );

		TiXmlComment comment;
		comment.Parse( "<!--comment-->", 0, TIXML_ENCODING_UNKNOWN );
		TiXmlComment commentCopy( comment );
		TiXmlComment commentAssign;
		commentAssign = commentCopy;
		XmlTest( "Copy/Assign: comment copy.", "comment", commentCopy.Value() );
		XmlTest( "Copy/Assign: comment assign.", "comment", commentAssign.Value() );

		TiXmlUnknown unknown;
		unknown.Parse( "<[unknown]>", 0, TIXML_ENCODING_UNKNOWN );
		TiXmlUnknown unknownCopy( unknown );
		TiXmlUnknown unknownAssign;
		unknownAssign.Parse( "incorrect", 0, TIXML_ENCODING_UNKNOWN );
		unknownAssign = unknownCopy;
		XmlTest( "Copy/Assign: unknown copy.", "[unknown]", unknownCopy.Value() );
		XmlTest( "Copy/Assign: unknown assign.", "[unknown]", unknownAssign.Value() );
		
		TiXmlText text( "TextNode" );
		TiXmlText textCopy( text );
		TiXmlText textAssign( "incorrect" );
		textAssign = text;
		XmlTest( "Copy/Assign: text copy.", "TextNode", textCopy.Value() );
		XmlTest( "Copy/Assign: text assign.", "TextNode", textAssign.Value() );

		TiXmlDeclaration dec;
		dec.Parse( "<?xml version='1.0' encoding='UTF-8'?>", 0, TIXML_ENCODING_UNKNOWN );
		TiXmlDeclaration decCopy( dec );
		TiXmlDeclaration decAssign;
		decAssign = dec;

		XmlTest( "Copy/Assign: declaration copy.", "UTF-8", decCopy.Encoding() );
		XmlTest( "Copy/Assign: text assign.", "UTF-8", decAssign.Encoding() );

		TiXmlDocument doc;
		elementCopy.InsertEndChild( textCopy );
		doc.InsertEndChild( decAssign );
		doc.InsertEndChild( elementCopy );
		doc.InsertEndChild( unknownAssign );

		TiXmlDocument docCopy( doc );
		TiXmlDocument docAssign;
		docAssign = docCopy;

		#ifdef TIXML_USE_STL
		std::string original, copy, assign;
		original << doc;
		copy << docCopy;
		assign << docAssign;
		XmlTest( "Copy/Assign: document copy.", original.c_str(), copy.c_str(), true );
		XmlTest( "Copy/Assign: document assign.", original.c_str(), assign.c_str(), true );

		#endif
	}	

	//////////////////////////////////////////////////////
#ifdef TIXML_USE_STL
	printf ("\n** Parsing, no Condense Whitespace **\n");
	TiXmlBase::SetCondenseWhiteSpace( false );
	{
		istringstream parse1( "<start>This  is    \ntext</start>" );
		TiXmlElement text1( "text" );
		parse1 >> text1;
开发者ID:huntriver,项目名称:TankVSBugs-CSE380-,代码行数:66,代码来源:xmltest.cpp

示例4: data

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.
    // sherm 100319: I changed this so that untagged top-level text is
    // parsed as a Text node rather than a parsing error. CDATA text was
    // already allowed at the top level so this seems more consistent.
    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.
        const unsigned char* pU = (const unsigned char*)p;
        if (    *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
             && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
             && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
        {
            encoding = TIXML_ENCODING_UTF8;
            useMicrosoftBOM = true;
        }
    }

    // Remember the start of white space in case we end up reading a text
    // element in a "keep white space" mode.
    const char* pWithWhiteSpace = p;
    p = SkipWhiteSpace( p, encoding );
    if ( !p )
    {
        SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
        return 0;
    }

    // sherm 100319: ignore all but the first Declaration
    bool haveSeenDeclaration = false;
    while ( p && *p )
    {
        TiXmlNode* node = 0;
        if ( *p != '<' )
        {   // sherm 100319: I added this case by stealing the code from
            // Element parsing; see above comment.
            // Take what we have, make a text element.
            TiXmlText* textNode = new TiXmlText( "" );

            if ( !textNode )
            {
                SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
                return 0;
            }

            if ( TiXmlBase::IsWhiteSpaceCondensed() )
            {
                p = textNode->Parse( p, &data, encoding );
            }
            else
            {
                // Special case: we want to keep the white space
                // so that leading spaces aren't removed.
                p = textNode->Parse( pWithWhiteSpace, &data, encoding );
            }

            if ( !textNode->Blank() ) {
                LinkEndChild( textNode );
                node = textNode;
            }
            else
                delete textNode;
        }
        else // We saw a '<', now identify what kind of tag it is.
        {
            TiXmlNode* node = Identify( p, encoding );
            if ( node )
            {
                p = node->Parse( p, &data, encoding );
                if (node->ToDeclaration()) {
                    if (haveSeenDeclaration) {
//.........这里部分代码省略.........
开发者ID:thomasklau,项目名称:simbody,代码行数:101,代码来源:tinyxmlparser.cpp

示例5: main


//.........这里部分代码省略.........
		XmlTest( "Copy/Assign: element assign #2.", "value", elementAssign.Attribute( "name" ) );
		XmlTest( "Copy/Assign: element assign #3.", 0, (int) elementAssign.Attribute( "foo" ) );

		TiXmlComment comment;
		comment.Parse( "<!--comment-->", 0, TIXML_ENCODING_UNKNOWN );
		TiXmlComment commentCopy( comment );
		TiXmlComment commentAssign;
		commentAssign = commentCopy;
		XmlTest( "Copy/Assign: comment copy.", "comment", commentCopy.Value() );
		XmlTest( "Copy/Assign: comment assign.", "comment", commentAssign.Value() );

		TiXmlUnknown unknown;
		unknown.Parse( "<[unknown]>", 0, TIXML_ENCODING_UNKNOWN );
		TiXmlUnknown unknownCopy( unknown );
		TiXmlUnknown unknownAssign;
		unknownAssign.Parse( "incorrect", 0, TIXML_ENCODING_UNKNOWN );
		unknownAssign = unknownCopy;
		XmlTest( "Copy/Assign: unknown copy.", "[unknown]", unknownCopy.Value() );
		XmlTest( "Copy/Assign: unknown assign.", "[unknown]", unknownAssign.Value() );
		
		TiXmlText text( "TextNode" );
		TiXmlText textCopy( text );
		TiXmlText textAssign( "incorrect" );
		textAssign = text;
		XmlTest( "Copy/Assign: text copy.", "TextNode", textCopy.Value() );
		XmlTest( "Copy/Assign: text assign.", "TextNode", textAssign.Value() );

		TiXmlDeclaration dec;
		dec.Parse( "<?xml version='1.0' encoding='UTF-8'?>", 0, TIXML_ENCODING_UNKNOWN );
		TiXmlDeclaration decCopy( dec );
		TiXmlDeclaration decAssign;
		decAssign = dec;

		XmlTest( "Copy/Assign: declaration copy.", "UTF-8", decCopy.Encoding() );
		XmlTest( "Copy/Assign: text assign.", "UTF-8", decAssign.Encoding() );

		TiXmlDocument doc;
		elementCopy.InsertEndChild( textCopy );
		doc.InsertEndChild( decAssign );
		doc.InsertEndChild( elementCopy );
		doc.InsertEndChild( unknownAssign );

		TiXmlDocument docCopy( doc );
		TiXmlDocument docAssign;
		docAssign = docCopy;

		#ifdef TIXML_USE_STL
		std::string original, copy, assign;
		original << doc;
		copy << docCopy;
		assign << docAssign;
		XmlTest( "Copy/Assign: document copy.", original.c_str(), copy.c_str(), true );
		XmlTest( "Copy/Assign: document assign.", original.c_str(), assign.c_str(), true );

		#endif
	}	

	//////////////////////////////////////////////////////
#ifdef TIXML_USE_STL
	printf ("\n** Parsing, no Condense Whitespace **\n");
	TiXmlBase::SetCondenseWhiteSpace( false );

	istringstream parse1( "<start>This  is    \ntext</start>" );
	TiXmlElement text1( "text" );
	parse1 >> text1;
开发者ID:bsmr-worldforge,项目名称:libwfut,代码行数:66,代码来源:xmltest.cpp

示例6: 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; 
		}
	}
}
开发者ID:PoppyRobot,项目名称:codeStudy,代码行数:95,代码来源:main.cpp

示例7: ConvertANSIXMLFile

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
}
开发者ID:HaoDrang,项目名称:GD,代码行数:85,代码来源:ProjectFileWriter.cpp


注:本文中的TiXmlDeclaration::Encoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。