×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 44

Thread: Reg:parsing

  1. #1
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Reg:parsing

    Hi im new to symbian im trying to parse the xml soap msg, im using the newl() function with the parameter...as follows,

    CXmlFileParser* CXmlFileParser::NewL( MXmlHandlerObserver& aObserver )

    how to initialize this newl function with parameter.... can i remove all the occurnce of tat aObserver, ill it create a problem???? thanks for any replies.....

  2. #2
    Registered User
    Join Date
    Feb 2007
    Location
    India
    Posts
    1,128

    Re: Reg:parsing

    Quote Originally Posted by moulii View Post
    Hi im new to symbian im trying to parse the xml soap msg, im using the newl() function with the parameter...as follows,

    CXmlFileParser* CXmlFileParser::NewL( MXmlHandlerObserver& aObserver )

    how to initialize this newl function with parameter.... can i remove all the occurnce of tat aObserver, ill it create a problem???? thanks for any replies.....
    Have a look WIKI example

    http://wiki.forum.nokia.com/index.ph..._CParser_class
    http://blogs.forum.nokia.com/index.p...&articleId=475

  3. #3
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    hi kishor thanks for ur reply, but actually i inherited tat class and i cleared tat......

    kishore actually first i used this parser wat u gave
    http://wiki.forum.nokia.com/index.ph..._CParser_class
    but its not working proper for soap messages for me tats y i went with the following code,

    Code:
    void CXmlFileParser::StartParsingL( const TDesC& aFileName, RFs& aFs )
    {
        RFile file;
        TBool iIsFirstChunk2=ETrue;
        if(! BaflUtils::FileExists(aFs,aFileName))
        	return;
        User::LeaveIfError( file.Open( aFs, aFileName, EFileRead ) );
        CleanupClosePushL( file );
        TInt size;
        User::LeaveIfError( file.Size( size ) );
        while( size != 0)
    	{
    		if(size > KFileBufferSize)
    		{
    			HBufC8* iBuffer2 = HBufC8::NewLC( KFileBufferSize );
    			TPtr8 bufferPtr( iBuffer2->Des() );
    			User::LeaveIfError( file.Read( bufferPtr ,KFileBufferSize) );  
    			if(iIsFirstChunk2)//first chunck to be parsed
    			{
    				iParser->ParseBeginL();
    				iIsFirstChunk2=EFalse;	
    			}
    			iParser->ParseL( *iBuffer2 );	
    			size -=KFileBufferSize;
    			CleanupStack::PopAndDestroy(iBuffer2);
    		}
    		else
    		{
    			HBufC8* iBuffer2 = HBufC8::NewLC(size );
    			TPtr8 bufferPtr( iBuffer2->Des() );
    			User::LeaveIfError( file.Read( bufferPtr ,size) );
    			if(iIsFirstChunk)
    			{
    				iParser->ParseBeginL();
    				iIsFirstChunk=EFalse;	
    			}
    			iParser->ParseL( *iBuffer2 );	
    			size=0;
    			CleanupStack::PopAndDestroy(iBuffer2);
    		}
    	}
    	iParser->ParseEndL();
    	CleanupStack::PopAndDestroy(1); // file
    }
    
    // --------------------------------------------------------------------------
       
    void CXmlFileParser::StartParsingWithAoL( const TDesC& aFileName, RFs& aFs )
        {
         // Remember to cancel any outstanding request first.
        if ( IsActive() )
            {
            Cancel();
            }
            
        User::LeaveIfError( iFile.Open( aFs, aFileName,
            EFileRead ) );
    
        // Create a buffer to store the file content.
        // Note that this method uses active object to read the file.
        // So we have to call SetActive() at the end. Then we call CParser::ParseL()
        // in RunL() method.
        delete iBuffer;
        iBuffer = 0;
        iBuffer = HBufC8::NewL( KFileBufferSize );
        TPtr8 bufferPtr( iBuffer->Des() );
        iFile.Read( bufferPtr, KFileBufferSize, iStatus );
        SetActive();
        iActiveSchedulerWait.Start();
    	// Tell the parser that we are about to parse a XML document.    
        iParser->ParseBeginL();
        }
    
    // --------------------------------------------------------------------------
    void CXmlFileParser::OnStartDocumentL( const RDocumentParameters& /*aDocParam*/,
            TInt aErrorCode )
        {
        // Display message to the screen stating that this is the starting of
        // XML document.
        _LIT( KOnStartDocumentL, "*** OnStartDocumentL ***\f" );
      //  //AppendText( KOnStartDocumentL );
        
        if ( KErrNone == aErrorCode )
            {
            // Do something if needed....
            }
        else
            {
            iObserver.OnParseErrorOccuredL( aErrorCode );
            }
        }
    
    // --------------------------------------------------------------------------
        
    void CXmlFileParser::OnEndDocumentL( TInt aErrorCode )
    {
        if ( KErrNone == aErrorCode )
            iObserver.HandleDocumentEndL();
        else
        	iObserver.OnParseErrorOccuredL( aErrorCode );
    }
    
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnStartElementL( const RTagInfo& aElement,
            const RAttributeArray& aAttributes, TInt aErrorCode )
    {
        if ( KErrNone == aErrorCode )
            {
    			HBufC8* iTagName=HBufC8::NewLC(aElement.LocalName().DesC().Length()+1);
    			*iTagName=aElement.LocalName().DesC();
    		//	PushTageL(*iTagName);
    			iObserver.HandleElementStartTagL(*iTagName);
    			CleanupStack::PopAndDestroy(iTagName);
            }
        else
            {
    			iObserver.OnParseErrorOccuredL( aErrorCode );
            }
    }
            
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnEndElementL( const RTagInfo &aElement, TInt aErrorCode )
    {
        if ( KErrNone == aErrorCode )
            {    
    			HBufC8* iTagName=HBufC8::NewLC(aElement.LocalName().DesC().Length()+1);
    			*iTagName=aElement.LocalName().DesC();
    			if(iContent.Length()>0)
    				{
    					iObserver.HandleElementContentL(iContent,*iTagName);
    					iContent.Zero();
    				}
    			//PopTag();			
    			iObserver.HandleElementEndTagL(*iTagName);
    			CleanupStack::PopAndDestroy(iTagName);
            }
    }
        
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnContentL( const TDesC8 &aBytes, TInt aErrorCode )
    {
    	if ( KErrNone == aErrorCode )
    		{
    			/*HBufC8* iTagName=HBufC8::NewLC(100);
    			*iTagName=TopTagName();*/					
    			iContent.Append(aBytes);
    			iContent.Trim();
    			/*CleanupStack::PopAndDestroy(iTagName);*/
    		}
    	else
    		{
    			iObserver.OnParseErrorOccuredL( aErrorCode );
    		}
    }
        
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnStartPrefixMappingL( const RString& /*aPrefix*/,
            const RString& /*aUri*/, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseErrorOccuredL( aErrorCode );
            }
        }
            
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnEndPrefixMappingL( const RString& /*aPrefix*/,
            TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseErrorOccuredL( aErrorCode );
            }
        }
        
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/,
            TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseErrorOccuredL( aErrorCode );
            }
        }
        
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnSkippedEntityL( const RString& /*aName*/,
            TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseErrorOccuredL( aErrorCode );
            }
        }
    
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnProcessingInstructionL( const TDesC8& /*aTarget*/,
            const TDesC8& /*aData*/, TInt aErrorCode )
        {
        if ( KErrNone == aErrorCode )
            {
            // Do something here...
            }
        else
            {
            iObserver.OnParseErrorOccuredL( aErrorCode );
            }
        }
    
    // --------------------------------------------------------------------------
    
    void CXmlFileParser::OnError( TInt aErrorCode )
        {
        _LIT( KErrorMessage, "*** OnError ***\f" );
        //AppendText( KErrorMessage );
        //iObserver.OnParseErrorOccuredL( aErrorCode );
        }
    
    // --------------------------------------------------------------------------
    
    TAny* CXmlFileParser::GetExtendedInterface( const TInt32 /*aUid*/ )
        {
        return 0;
        }
    
    void CXmlFileParser::PushTageL(const TDesC8& aTagName)
    {
    	iTagNames->AppendL(aTagName);
    	
    }
    
    void CXmlFileParser::PopTag()
    {
    	iTagNames->Delete(iTagNames->Count() - 1);
    	
    }
    Last edited by wizard_hu_; 2010-08-27 at 09:24. Reason: code tags for preserving indentation

  4. #4
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    and now stuck with calling the function

    void CXmlFileParser::StartParsingL( const TDesC& aFileName, RFs& aFs )

    wat should i pass for the parameter RFs& aFs ... as im new i don have any idea with it...can u tell me how to call tat function..

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Reg:parsing

    RFs is a session to the File Server, you will see this class frequently.
    The simplest thing is having your own, Connect and Close
    Code:
    RFs fs;
    fs.Connect();
    
    // use it
    
    fs.Close();
    in practice there can be errors, so the Cleanup Stack should be used, and Connect may also fail in theory
    Code:
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    
    // use it
    
    CleanupStack::PopAndDestroy();
    Since it is a frequently needed object, the GUI application framework has an RFs which you can get and use at any time,
    Code:
    CCoeEnv::Static()->FsSession()
    gives you an "RFs&" - this object is not owned by you, so do not put it on the Cleanup Stack and do not Close it either.

    Whichever variant you use, you may get some errors about that certain entities (like RFs and CCoeEnv) are totally unknown, in that case check the SDK Help (or the online documentation on http://library.forum.nokia.com) to see which headers and libraries are required.

  6. #6
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    hi wizard i tried using the following method provided by kishor

    http://wiki.forum.nokia.com/index.ph..._CParser_class

    in tat i called the following function for parsing,

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

    // Create a buffer to store the file content.
    // Note that this method uses active object to read the file.
    // So we have to call SetActive() at the end. Then we call CParser::ParseL()
    // in RunL() method.
    delete iBuffer;
    iBuffer = 0;
    iBuffer = HBufC8::NewL( KFileBufferSize );
    TPtr8 bufferPtr( iBuffer->Des() );
    iFile.Read( bufferPtr, KFileBufferSize, iStatus );
    SetActive();

    // Tell the parser that we are about to parse a XML document.
    iParser->ParseBeginL();
    }
    in this function wre the parsing starts... whn i debug i couldn't find any change in my console too....wats the problem..my application runs fine with no errors....but wre parsing is done??? waiting for ur reply.....

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Reg:parsing

    Do you have anything what should print, list, etc. the result? For the debugging part you could put breakpoints in the OnSomething/L methods, especially OnError, OnStart/End/Document/ElementL and OnContentL.

  8. #8
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    Quote Originally Posted by wizard_hu_ View Post
    Do you have anything what should print, list, etc. the result? For the debugging part you could put breakpoints in the OnSomething/L methods, especially OnError, OnStart/End/Document/ElementL and OnContentL.


    void CXmlHandler::StartParsingWithAoL( const TDesC& aFileName )

    wre does those methods called in this function????
    i kept breakpoints in all the functions but it does not moves to any of the methods.... then wre it is supposed to parse my xml??? im confused wizard..
    Last edited by moulii; 2010-08-27 at 11:29.

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Reg:parsing

    CParser::ParseL collects the data you are feeding to it, and from time to time (when a complete tag is feed to it) it calls those callback methods.
    Is your code a GUI code? This active object-based implementation requires a running Active Scheduler loop, something you have to initialize and start manually from GUI-less code. Also note that CCoeEnv does not work in non-GUI code.

  10. #10
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    Quote Originally Posted by wizard_hu_ View Post
    CParser::ParseL collects the data you are feeding to it, and from time to time (when a complete tag is feed to it) it calls those callback methods.
    Is your code a GUI code? This active object-based implementation requires a running Active Scheduler loop, something you have to initialize and start manually from GUI-less code. Also note that CCoeEnv does not work in non-GUI code.
    k wizard mine is the gui application wizard, actually i kept break points in all the other functions in tat api....and i could find out tat none of the methods r called !!!!!!!!!!!!!!!!!!!! wat makes problem wizard???

    and parsing method should return somethin.... but i don find anythin like tat the function

    StartParsingWithAoL( const TDesC& aFileName ).... am i correct???? wizard...
    Last edited by moulii; 2010-08-27 at 12:54.

  11. #11
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    does anybody worked with it plz come forward.......help me out of this problem.... i need to know wthr the soap message can be parsed by this... plz help me out...
    Last edited by moulii; 2010-08-27 at 14:18.

  12. #12
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    TBuf<900> SMSText;
    TBuf<20> inputtext1;
    _LIT(KTxt2,"success");
    inputtext1.Copy(KTxt2);

    TBuf<150> Text;

    SMSText.Copy(_L("<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><ImportIncomingSMSResponse xmlns='http://www.atom8itsolutions.com/'><ImportIncomingSMSResult>"));
    SMSText.Append( inputtext1);
    Text.Copy(_L("</ImportIncomingSMSResult></ImportIncomingSMSResponse></soap:Body></soap:Envelope>"));
    SMSText.Append(Text);
    _LIT(KFileSpec,"c:\\data\\parse.txt");
    TInt pos = 0;
    RFs fs;
    RFile file;

    _LIT( KWorksDataFile,"C:\\data\\parse.txt");

    RFs fsSession;
    TFileText txt_file;

    User::LeaveIfError(fsSession.Connect());

    TInt err=file.Open(fsSession, KWorksDataFile, EFileWrite);
    if(err!=KErrNone)
    err=file.Create(fsSession, KWorksDataFile, EFileWrite);

    txt_file.Set(file);
    txt_file.Write(SMSText);//Write seeks to end of file

    fsSession.Close();



    iXmlFileParser->StartParsingWithAoL(KWorksDataFile);

    i called this parse function like this.......the method gets called and it works fine....but i couldn't know were the xml is parsed..... can any one help me plz.......

  13. #13
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,544

    Re: Reg:parsing

    Quote Originally Posted by moulii View Post
    the method gets called and it works fine....but i couldn't know were the xml is parsed..... can any one help me plz.......
    Consider the suggestion in post #7 for this.

    Please always post your code within code tags so they are readable.

  14. #14
    Regular Contributor
    Join Date
    Aug 2010
    Posts
    120

    Re: Reg:parsing

    Quote Originally Posted by Symbian_Neil View Post
    Consider the suggestion in post #7 for this.

    Please always post your code within code tags so they are readable.
    yes neil u r rte?? but the methods onstartelement and onendelement() functions r not even called i kept breakpoints in tat functions, from tat i can came to know tat those methods r not called... there only i can find the element parsed so now how can i put breakpoints over there??? this is the problem im getting neil
    Last edited by moulii; 2010-08-30 at 10:59.

  15. #15
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,544

    Re: Reg:parsing

    Quote Originally Posted by moulii View Post
    yes nail u r rte?? but the methods onstartelement and onendelement() functions r not even called i kept breakpoints in tat functions, from tat i can came to know tat those methods r not called... there only i can find the element parsed so now how can i put breakpoints over there??? this is the problem im getting neil
    How about pressing F5 on when it reaches
    Code:
    iXmlFileParser->StartParsingWithAoL(KWorksDataFile);
    If its not then your claim in post #12 that "method gets called and it works fine might not be true..unfortunately.

    Edit: btw, if you are unable to comprehend names, I suggest you can avoid it completely
    Last edited by Symbian_Neil; 2010-08-30 at 11:03. Reason: an additional suggestion!!

Similar Threads

  1. Reg:soap message parsing
    By gurubai in forum Symbian
    Replies: 3
    Last Post: 2010-08-10, 15:54
  2. Reg:parsing
    By ranjini in forum Symbian
    Replies: 8
    Last Post: 2010-08-09, 13:12
  3. Reg:parsing
    By gurubai in forum Symbian
    Replies: 2
    Last Post: 2010-07-08, 12:20
  4. Reg: issue in parsing xml
    By raguuu in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2010-07-06, 13:05
  5. Reg non repudiation
    By praveena in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2006-02-22, 22:42

Posting Permissions

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