⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycontenthandler.cpp

📁 Symbian下解析XML的代码,完全用API解析
💻 CPP
字号:
/*
============================================================================
 Name        : MyContentHandler.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CMyContentHandler implementation
============================================================================
*/

#include "MyContentHandler.h"

#include <aknnotewrappers.h>

//Constants
const TInt KBufferSize     = 1024; // buffer size to store the result of
// XML parsing -> the actual buffer size
// can expand if needed (see AppendText())

const TInt KFileBufferSize = 1024; // buffer size for file reading

const TInt KOverheadLen    = 4; // length of (KOpeningTag + KClosingTag
//            + KSlash + KEndOfLine)


CMyContentHandler::CMyContentHandler()
{
	// No implementation required
}


CMyContentHandler::~CMyContentHandler()
{
}

CMyContentHandler* CMyContentHandler::NewLC()
{
	CMyContentHandler* self = new (ELeave)CMyContentHandler();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CMyContentHandler* CMyContentHandler::NewL()
{
	CMyContentHandler* self=CMyContentHandler::NewLC();
	CleanupStack::Pop(); // self;
	return self;
}

void CMyContentHandler::ConstructL()
{

}
void CMyContentHandler::AppendText( const TDesC& aText )
{
	/*TPtr displayResultPtr( iDisplayResult->Des() );
	if ( displayResultPtr.Length() + aText.Length() > displayResultPtr.MaxLength() )
	{
		iDisplayResult = iDisplayResult->ReAllocL( displayResultPtr.MaxLength()+ KBufferSize );
		displayResultPtr.Set( iDisplayResult->Des() );
	}   
	displayResultPtr.Append( aText );*/
}

void CMyContentHandler::OnStartDocumentL( const RDocumentParameters &aDocParam, TInt aErrorCode )
{
	_LIT( KOnStartDocumentL, "*** OnStartDocumentL ***\f" );
	//iDisplayResult->Des().Zero();
	AppendText( KOnStartDocumentL );

}
void CMyContentHandler::OnEndDocumentL( TInt aErrorCode )
{
}
void CMyContentHandler::OnStartElementL( const RTagInfo &aElement, const RAttributeArray &aAttributes, TInt aErrorCode )
{
	 //判断是否是presence标签
	 if( 0 == (aElement.LocalName().DesC().Compare(_L8("presence"))) )
	 {
	  TInt count = aAttributes.Count(); 

	  for(TInt i=0; i<count; i++)
	  {
		  TBuf8<20> name = aAttributes[i].Attribute().LocalName().DesC();
		  //获得"entity",即联系人ID
		  if((name.Compare(_L8("entity")))== 0 )
		  {
			  TBuf8<100> value = aAttributes[i].Value().DesC();
			  /*this->Contact.Copy(value);*/
		  }		  
	  }
	 }
	if( 0 ==(aElement.LocalName().DesC().Compare(_L8("basic"))))
	 {
	 //   //设置联系人状态已经开始解析
		//this->iStateStored = ETrue ;
	 }

	
	
}
void CMyContentHandler::OnEndElementL( const RTagInfo &aElement, TInt aErrorCode )
{

}

void CMyContentHandler::OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
{
	//HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT );
	//
	//// Show the information Note with
	//// textResource loaded with StringLoader.
	//CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
	//informationNote->ExecuteLD( *textResource );

	//// Pop HBuf from CleanUpStack and Destroy it.
	//CleanupStack::PopAndDestroy( textResource );
	HBufC* buffer = HBufC::NewLC(aBytes.Length()+1);
	TPtr bufferPtr( buffer->Des() );
	bufferPtr.Copy( aBytes );
	//TPtr bufferPtr( buffer->Des() );
	//buffer->Des().Append(aBytes);
	//bufferPtr.Copy( aBytes );
	CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
   
	informationNote->ExecuteLD(* buffer);
	//delete informationNote;
	CleanupStack::PopAndDestroy(); // buffer
}
void CMyContentHandler::OnStartPrefixMappingL( const RString &aPrefix, const RString &aUri, TInt aErrorCode )
{
}
void CMyContentHandler::OnEndPrefixMappingL( const RString &aPrefix, TInt aErrorCode )
{
}
void CMyContentHandler::OnIgnorableWhiteSpaceL( const TDesC8 &aBytes, TInt aErrorCode )
{
}
void CMyContentHandler::OnSkippedEntityL( const RString &aName, TInt aErrorCode )
{
}
void CMyContentHandler::OnProcessingInstructionL( const TDesC8 &aTarget, const TDesC8 &aData,TInt aErrorCode)
{
}
void CMyContentHandler::OnError( TInt aErrorCode )
{
}
TAny *CMyContentHandler::GetExtendedInterface( const TInt32 aUid )
{

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -