Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Super Contributor deepchand86's Avatar
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889
    Hai ppl...

    I am trying to read an Xml file.
    I hav been using RFileReadstream along with RFile.

    Bt the thing is i want the whole contents of the file in
    a single buffer(HBufC*)..i.e in a single read i should be able to extract the contents of the file without any looping,etc...

    Could anyone suggest me what to do????

  2. #2
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,667
    And how did you try it earlier, and what actually went wrong with that approacj ?

  3. #3
    Nokia Developer Champion kkrish's Avatar
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,029
    Hi,

    You can use the following method. Here is the link

    or you can also use CParser to parse xml

  4. #4
    Regular Contributor rkmohanty's Avatar
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156
    This link may help you, try it out

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

  5. #5
    Super Contributor deepchand86's Avatar
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889
    Consider the following code....

    TInt iSize = read.Source()->SizeL();
    HBufC* buf = HBufC::NewL(read, iSize) ;
    TPtr16 pBuf = buf->Des() ;
    read >> pBuf;

    On execution....
    I m able to get the file size i.e iSize correctly(27 KB).
    In the next line i have passed it as a parameter...

    But when checked buf consisted only of 15 characters..It is reading only a little..and also the consecutive code too..
    Rather than going for loops can't i read it as a whole...

  6. #6
    Super Contributor deepchand86's Avatar
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889
    No..No...
    Consider the case of text file itself...
    Don't specialize for xml file..

  7. #7
    Nokia Developer Champion kkrish's Avatar
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,029
    Quote Originally Posted by deepchand86 View Post
    Consider the following code....

    TInt iSize = read.Source()->SizeL();
    HBufC* buf = HBufC::NewL(read, iSize) ;
    TPtr16 pBuf = buf->Des() ;
    read >> pBuf;

    On execution....
    I m able to get the file size i.e iSize correctly(27 KB).
    In the next line i have passed it as a parameter...

    But when checked buf consisted only of 15 characters..It is reading only a little..and also the consecutive code too..
    Rather than going for loops can't i read it as a whole...
    Hi,

    Not getting you exactly what you are trying to say. are you not able to read all the content of the file so just increase the file size let suppose make it double by multiply 2.

  8. #8
    Super Contributor deepchand86's Avatar
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889
    No kkrish..

    I will be able to read the file if i construct a loop and use the above code...

    But my question is why can't i read it in a single call
    to HBufC constructor whose second argument is the file size i m going to read... But it is not reading the whole contents into the buffer...

    It's only reading a little into the buffer...
    Hope U Understand this....

  9. #9
    Registered User Kavit Patel's Avatar
    Join Date
    Nov 2007
    Posts
    444
    Hi Deep,

    TInt iSize = read.Source()->SizeL();
    What is your "read" here?

    Also you can take the file size by using RFile::Size() method.

    Regards,
    Kavit.

  10. #10
    Regular Contributor rkmohanty's Avatar
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156
    try to use this one by using RFile object
    TInt Read(TDes8 &aDes) const;

    you can read whole content of a file at a time into your TDes8 type object.

  11. #11
    Super Contributor deepchand86's Avatar
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889
    k mohanty...

    But while creating an TDes8 object..i need to mention the size..
    Am i right...

    Consider the case in which i m not sure abt the file size...
    Eventhough i get the Filesize...
    How do i create a Descriptor with that filesize dynamically???

  12. #12
    Registered User Kavit Patel's Avatar
    Join Date
    Nov 2007
    Posts
    444
    For dynamic size you must have to use heap descriptors.
    That is HBuC.
    And you can get the file size as I mentioned above.
    This size can be used as the size parameter to create the heap descriptor.

    Regards,
    Kavit.

  13. #13
    Regular Contributor rkmohanty's Avatar
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156
    Ya kavit is right.
    you go with him , you'll get result.

  14. #14
    Super Contributor deepchand86's Avatar
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889
    RFile myfile;
    RFs fss;
    User::LeaveIfError(fss.Connect());
    CleanupClosePushL(fss);
    User::LeaveIfError(myfile.Open(fss,KMyFile,EFileShareExclusive|EFileRead ));
    TInt size ;
    myfile.Size(size);


    HBufC8* buf = HBufC8::NewL(size) ;
    TPtr8 pBuf = buf->Des();
    myfile.Read(pBuf);


    I m using the above code to read the file.
    But it is aborting(No source available..) on the last line in the debug mode....
    (Read operation)....Any thing wrong in the above code...

  15. #15
    Regular Contributor rkmohanty's Avatar
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156
    Quote Originally Posted by deepchand86 View Post
    RFile myfile;
    RFs fss;
    User::LeaveIfError(fss.Connect());
    CleanupClosePushL(fss);
    User::LeaveIfError(myfile.Open(fss,KMyFile,EFileShareExclusive|EFileRead ));
    TInt size ;
    myfile.Size(size);


    HBufC8* buf = HBufC8::NewL(size) ;
    TPtr8 pBuf = buf->Des();
    myfile.Read(pBuf);


    I m using the above code to read the file.
    But it is aborting(No source available..) on the last line in the debug mode....
    (Read operation)....Any thing wrong in the above code...



    you are correct in code, its running perfect for me.
    KMyFile is the path where your file exist,
    you check that path file is there or not
    Last edited by rkmohanty; 2008-08-04 at 10:54.

Page 1 of 2 12 LastLast

Similar Threads

  1. [moved] Theme Studio Error
    By TalJ in forum Themes/Carbide.ui
    Replies: 2
    Last Post: 2009-09-06, 03:39
  2. Problem with pyobfuscate
    By JOM in forum Python
    Replies: 3
    Last Post: 2008-06-20, 22:47
  3. problem when importing from carbide c++ to vs 2003!
    By misfit.physics in forum Symbian Tools & SDKs
    Replies: 12
    Last Post: 2008-02-19, 09:45
  4. creating list box error reading from file
    By pulkitjain in forum Symbian C++
    Replies: 2
    Last Post: 2008-01-26, 05:23
  5. Reading from binary file, how to manage file ending?
    By tiia1234 in forum Symbian C++
    Replies: 2
    Last Post: 2007-12-28, 15:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved