×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    259

    Retrieving data in MyXmlParser Example

    I was trying the example of MyXmlParser from the link
    http://wiki.forum.nokia.com/index.ph...arser_Class%3F

    and I have the source file XmlHandler.cpp as
    HTML Code:
    // INCLUDE FILES
    #include <coemain.h>
    #include <f32file.h>
    #include "EIKAPPUI.H"
    #include "XmlHandler.h"
    #include <aknmessagequerydialog.h>
    #include <aknnotewrappers.h>
    #include "MyXmlParserAppUi.h"
    #include "COEAUI.H"
    #include "XMLtoSymbianComboView.h"
    
    #include "MyXmlParserAppView.h"
    #include <utf.h>  
    // CONSTANTS
    const TInt KBufferSize     = 1024; 
                                       
    const TInt KFileBufferSize = 1024; 
    
    const TInt KOverheadLen    = 4; 
                                    
    
    _LIT(KOpeningTag, "<" );
    _LIT(KClosingTag, ">" );
    _LIT(KSlash,      "/" );
    _LIT(KEndOfLine,  "\f" ); 
    
    _LIT8( KXmlMimeType, "text/xml" );
    
    // METHODS DEFINITION
    
    
    
    CXmlHandler* CXmlHandler::NewL( MXmlHandlerObserver& aObserver )
        {
        CXmlHandler* self = CXmlHandler::NewLC( aObserver );
        CleanupStack::Pop();
        return self;
        }
    
    CXmlHandler* CXmlHandler::NewLC( MXmlHandlerObserver& aObserver )
        {
        CXmlHandler* self = new ( ELeave ) CXmlHandler( aObserver );
        CleanupStack::PushL( self );
        self->ConstructL();
        return self;
        }
    
    
    
    CXmlHandler::~CXmlHandler()
        {
        Cancel();
        delete iParser;
        delete iDisplayResult;
        delete iBuffer;
        }
    
    
    
    CXmlHandler::CXmlHandler( MXmlHandlerObserver& aObserver )
        :CActive( EPriorityStandard ),
        iObserver( aObserver ),
        iParser( 0 ),
        iDisplayResult( 0 ),
        iState( EIdle )
        {
        CActiveScheduler::Add( this );
        }
    
    
    
    void CXmlHandler::DoCancel()
        {
        iParser->ParseEndL();
        iFile.Close();
        delete iBuffer;
        iBuffer = 0;
        }
    
    
    
    void CXmlHandler::RunL()
        {
        if ( KErrNone == iStatus.Int() )
            {
         
            if ( iBuffer->Length() == 0)
                {
                iParser->ParseEndL();
                iFile.Close();
                delete iBuffer;
                iBuffer = 0;
                }
                
           
            else
                {
              
                iParser->ParseL( *iBuffer );
                
                
                TPtr8 bufferPtr( iBuffer->Des() );
                iFile.Read( bufferPtr, KFileBufferSize, iStatus );
                
              
                SetActive();
                }
            }
        else
            {
            iObserver.OnParseCompleted( iStatus.Int() );
            }
        }
    
    
    
    void CXmlHandler::ConstructL()
        {
        iParser = CParser::NewL( KXmlMimeType, *this );
        iDisplayResult = HBufC::NewL( KBufferSize );
        }
    
    
       
    void CXmlHandler::StartParsingL( const TDesC& aFileName )
        {
       
        RFile file;
        User::LeaveIfError( file.Open( CCoeEnv::Static()->FsSession(), aFileName,
            EFileRead ) );
        CleanupClosePushL( file );
        
        iDisplayResult->Des().Zero();
        TInt size;
        User::LeaveIfError( file.Size( size ) );
        delete iBuffer;
        iBuffer = 0;
        iBuffer = HBufC8::NewL( size );
        TPtr8 bufferPtr( iBuffer->Des() );
        User::LeaveIfError( file.Read( bufferPtr ) );
        
        CleanupStack::PopAndDestroy(); // file
        
        // Now, we have the whole file content in iBuffer.
        // We are ready to parse the XML content.
        iParser->ParseBeginL();
        iParser->ParseL( *iBuffer );
        
        // Since we read the whole file contents within one-shot,
        // we can call ParseEndL() right after calling ParseL().
        iParser->ParseEndL();
        
     
        }
    
       
    void CXmlHandler::StartParsingWithAoL( const TDesC& aFileName )
        {
         // Remember to cancel any outstanding request first.
        if ( IsActive() )
            {
            Cancel();
            }
            
        User::LeaveIfError( iFile.Open( CCoeEnv::Static()->FsSession(), aFileName,
            EFileRead ) );
    
      
        iDisplayResult->Des().Zero();
        delete iBuffer;
        iBuffer = 0;
        iBuffer = HBufC8::NewL( KFileBufferSize );
        TPtr8 bufferPtr( iBuffer->Des() );
        iFile.Read( bufferPtr, KFileBufferSize, iStatus );
        SetActive();
    
    	
        iParser->ParseBeginL();
       
        }
    
    
    
    void CXmlHandler::OnStartDocumentL( const RDocumentParameters& /*aDocParam*/,
            TInt aErrorCode )
        {
       
        _LIT( KOnStartDocumentL, "*** OnStartDocumentL ***\f" );
        AppendText( KOnStartDocumentL );
        
        if ( KErrNone == aErrorCode )
            {
            // Do something if needed....
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
    
    
        
    void CXmlHandler::OnEndDocumentL( TInt aErrorCode )
        {
      
        _LIT( KOnEndDocumentL, "*** OnEndDocumentL ***\f" );
        AppendText( KOnEndDocumentL );
        
        if ( KErrNone == aErrorCode )
            {
            // Do something here if needed....
            }
            
        iObserver.OnParseCompleted( aErrorCode );
        }
    
    
    
    void CXmlHandler::OnStartElementL( const RTagInfo& aElement,
            const RAttributeArray& aAttributes, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            
            
          
           
           
            	     
        }
        
    
    
    
    
    void CXmlHandler::CalledComboL()
    	{
    	
    	_LIT(KMenuItem,"%d is selected");
    	TBuf<20> buf;
    	buf.Format(KMenuItem(), NumberofElementXmlHandler);       
    	CAknInformationNote* info = new (ELeave) CAknInformationNote;
    	info->ExecuteLD(buf);
    	
    	}
    
    
    
    
    void CXmlHandler::OnEndElementL( const RTagInfo &aElement, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // If we find the end of an element, we write it to the screen,
            // for example: "</tag>"
            AppendTag( aElement.LocalName().DesC(), ETrue );
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        
        }
        
    
    
    void CXmlHandler::OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
          
            HBufC* buffer = HBufC::NewLC( aBytes.Length() + 1 );
            TPtr bufferPtr( buffer->Des() );
            bufferPtr.Copy( aBytes );
            AppendText( *buffer );
            CleanupStack::PopAndDestroy(); // buffer
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
        
    
    
    void CXmlHandler::OnStartPrefixMappingL( const RString& /*aPrefix*/,
            const RString& /*aUri*/, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
            
    
    
    void CXmlHandler::OnEndPrefixMappingL( const RString& /*aPrefix*/,
            TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
        
    
    
    void CXmlHandler::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/,
            TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
        
    
    
    void CXmlHandler::OnSkippedEntityL( const RString& /*aName*/,
            TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
    
    
    
    void CXmlHandler::OnProcessingInstructionL( const TDesC8& /*aTarget*/,
            const TDesC8& /*aData*/, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseCompleted( aErrorCode );
            }
        }
    
    
    void CXmlHandler::OnError( TInt aErrorCode )
        {
        _LIT( KErrorMessage, "*** OnError ***\f" );
        AppendText( KErrorMessage );
        iObserver.OnParseCompleted( aErrorCode );
        }
    
    
    
    TAny* CXmlHandler::GetExtendedInterface( const TInt32 /*aUid*/ )
        {
        return 0;
        }
    
    
    
    void CXmlHandler::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 CXmlHandler::AppendTag( const TDesC8& /*aTag*/, TBool /*aIsClosingTag*/ )
        {
        // Instantiate buffer to display tag information.
        /*HBufC* buffer = HBufC::NewLC( aTag.Length()
            + ( ( aIsClosingTag ) ? KOverheadLen : KOverheadLen - 1 ) );
        TPtr bufferPtr( buffer->Des() );
            
        // Convert tag name from TDesC8 to TDesC16.
        bufferPtr.Copy( aTag );
            
        // Add opening tag.
        if ( aIsClosingTag )
            {
            bufferPtr.Insert( 0, KSlash );
            }
        bufferPtr.Insert( 0, KOpeningTag );
            
        // Add closing tag.
        bufferPtr.Append( KClosingTag );
        bufferPtr.Append( KEndOfLine );
            
        // Add to the result text and then destroy it.
        AppendText( *buffer );
        CleanupStack::PopAndDestroy(); // buffer*/
        }
    
    // End of File

    Can anyone please tell me how I can retrieve the data
    "What is your gender?"
    from
    <TextView>What is your gender?</TextView>

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Retrieving data in MyXmlParser Example

    try not to multi post http://discussion.forum.nokia.com/fo...d.php?t=177041. help keep this DiBo clean.

Similar Threads

  1. Replies: 9
    Last Post: 2010-06-10, 12:39
  2. help~~~about the CMdaAudioInputStream
    By Dragon_L in forum Symbian Media (Closed)
    Replies: 14
    Last Post: 2008-11-05, 06:11
  3. Retrieving data from the database..
    By remesh in forum Symbian
    Replies: 3
    Last Post: 2008-10-11, 10:24
  4. Retrieving sorted data
    By asheeshv in forum Symbian
    Replies: 0
    Last Post: 2005-04-12, 08:31
  5. Replies: 1
    Last Post: 2004-09-18, 12:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×