×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    136

    XML Parsing in Symbian C++

    Hi,
    I am trying to parse an xml file like this
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <persons>
        <person id="1">
            <firstname>John</firstname>
            <surname>Doe</surname>
            <email>john.doe@example.com</email>
            <website>http://en.wikipedia.org/wiki/John_Doe</website>
        </person>
        <person id="2">
            <firstname>sandra</firstname>
            <surname>law</surname>
            <email>sandra.law@example.com</email>
            <website>http://en.wikipedia.org/wiki/sandra_law</website>
        </person>
        <person id="3">
            <firstname>Matti</firstname>
            <surname>Meikalainen</surname>
            <email>matti.meikalainen@example.com</email>
            <website>http://fi.wikipedia.org/wiki/Matti_Meikalainen</website>
        </person>
    </persons>
    Here is the code
    Code:
    _LIT8(KXMLServerStart,"<person>");
    _LIT8(KXMLServerEnd,"</person>");
    
    void CXMLParsingTest1AppUi::xmlparsing()
    	{
    
    	TInt count =0;
    	RFs fs;
    	User::LeaveIfError(fs.Connect());
    	CleanupClosePushL(fs);
    	RFile iFile;
    	User::LeaveIfError(
    			iFile.Open(fs, KFileXML, EFileShareExclusive | EFileRead));
    
    	TInt fileSize(0);
    	iFile.Size(fileSize);
    	if (fileSize <= 0)
    		{
    		iFile.Close();
    		return;
    		}
    	HBufC8* aHBufData = HBufC8::NewLC(fileSize);
    	TPtr8 aXmlData(aHBufData->Des());
    	iFile.Read(aXmlData);
    
    	if (aXmlData.Length() > 0)
    		{
    TBuf16<300> tempBuf;
    		TInt startPos = aXmlData.Find(KXMLServerStart)
    				+ KXMLServerStart().Length();
    		TInt endPos = aXmlData.Find(KXMLServerEnd);
    
    	while (endPos > startPos)
    			{
    
    			tempBuf.Copy(aXmlData.Mid(startPos, (endPos - startPos)));
    			CAknInformationNote *info = new (ELeave) CAknInformationNote();
    			info->ExecuteLD(tempBuf);
    			endPos = aXmlData.Find(KXMLServerEnd);
    
    			}
    
    		}
    	iFile.Close();
    	CleanupStack::PopAndDestroy(2);
    	}
    My concept is that I want to find the tag and get the mid value of it. i am able to get it but if there are multiple tag of same type in different items then I am getting some issue.
    how do i know whether the file pointer is at the End of File or not.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: XML Parsing in Symbian C++

    Note that there are built-in XML parser API-s, you can find various discussions and articles about them. Here is a recent one: http://discussion.forum.nokia.com/fo...08-XML-parsing. The relatively long thread, http://discussion.forum.nokia.com/fo...in-XML-parsing contains some actual example codes for parsing actual data.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    136

    Re: XML Parsing in Symbian C++

    I have check these already and these are done using http://wiki.forum.nokia.com/index.ph..._CParser_class. I can parse Xml like below using CPraser. But not able to parse my xml. Do you know how do I get the inforamtion whether i am at the end of file or not
    Code:
    <ComboBox name="Sex">
        <ListItem value="M" text="Male" selected="true" />
        <ListItem value="F" text="Female" />
        <ListItem value="F" text="Female" />
    </ComboBox>

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: XML Parsing in Symbian C++

    With CParser you get an OnEndDocumentL call when the parser detects the end of the document.
    With a custom parser, you can also build on that closing the main document element implies end of file.
    On file reading level, RFile::Read produces an empty descriptor when there is nothing left.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    136

    Re: XML Parsing in Symbian C++

    Quote Originally Posted by wizard_hu_ View Post
    With CParser you get an OnEndDocumentL call when the parser detects the end of the document.
    With a custom parser, you can also build on that closing the main document element implies end of file.
    On file reading level, RFile::Read produces an empty descriptor when there is nothing left.
    I am using RFile to parse. Actually I am reading the file and finding a particulr tag , what is that empty descriptor in RFile?
    I my program I have to parse different kinds of XML those are not at all standard XML. So i need to create my own parse. So I am trying to read the file and get the tag from it.
    It would be so nice of you, if you could see once my code in Post #1 and let me know whether it will parse the xml in post #1 or not

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    136

    Re: XML Parsing in Symbian C++

    i am using the below code
    Code:
    void CXMLParsingTest1AppUi::xmlparsing()
    	{
    
    	TInt count =0;
    	RFs fs;
    	User::LeaveIfError(fs.Connect());
    	CleanupClosePushL(fs);
    	RFile iFile;
    	User::LeaveIfError(
    			iFile.Open(fs, KFileXML, EFileShareExclusive | EFileRead));
    
    	TInt fileSize(0);
    	iFile.Size(fileSize);
    	if (fileSize <= 0)
    		{
    		iFile.Close();
    		return;
    		}
    	HBufC8* aHBufData = HBufC8::NewLC(fileSize);
    	TPtr8 aXmlData(aHBufData->Des());
    	iFile.Read(aXmlData);
    
    	if (aXmlData.Length() > 0)
    		{
    		
    					
    					
    		TBuf16<300> tempBuf;
    		TInt startPos = aXmlData.Find(KXMLServerStart)
    				+ KXMLServerStart().Length();
    		TInt endPos = aXmlData.Find(KXMLServerEnd);
    
    		for (TInt i=0;i<3;i++)
    	if(endPos > startPos)
    			{
    
    			tempBuf.Copy(aXmlData.Mid(startPos, (endPos - startPos)));
    			
    					
    			}
    
    		}
    	iFile.Close();
    	CleanupStack::PopAndDestroy(2);
    	}
    but everytime it gives me the same element parsed?
    Please help me to get this xml parsed

  7. #7
    Registered User
    Join Date
    Oct 2010
    Posts
    136

    Re: XML Parsing in Symbian C++

    I have checked my above code and its getting the same first element every time i use the Find is there anything like FindNext, I mean when I find the first element the file pointer should search in the next place.
    please help me

  8. #8
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: XML Parsing in Symbian C++

    Quote Originally Posted by v-6 View Post
    I have check these already and these are done using http://wiki.forum.nokia.com/index.ph..._CParser_class. I can parse Xml like below using CPraser. But not able to parse my xml. Do you know how do I get the inforamtion whether i am at the end of file or not
    Code:
    <ComboBox name="Sex">
        <ListItem value="M" text="Male" selected="true" />
        <ListItem value="F" text="Female" />
        <ListItem value="F" text="Female" />
    </ComboBox>
    You can even parse multiple element as well as child element of XML. You just check value of each tag on OnStartElementL() method. Just once check that example again. http://wiki.forum.nokia.com/index.ph..._CParser_class

  9. #9
    Registered User
    Join Date
    Apr 2011
    Location
    Hyderabad, IN
    Posts
    36

    Re: XML Parsing in Symbian C++

    Quote Originally Posted by savaj View Post
    You can even parse multiple element as well as child element of XML. You just check value of each tag on OnStartElementL() method. Just once check that example again. http://wiki.forum.nokia.com/index.ph..._CParser_class
    Iam facing the same problem I want to parse the given xmxl nodes below


    <root><settings><appurl>http://www.yupptv.com/</appurl><adurl>http://www.webmobiads.com/bmobile/iphonead.aspx</adurl><adinterval>600.0</adinterval></settings><channel><name>NewsX </name><type>News Channel</type><language>English</language><image>http://www.yupptv.com/img/newsx.png</image><link>rtsp://94.75.250.53:80/live136/newsx2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>NewsX </name><type>News Channel</type><language>English</language><image>http://www.yupptv.com/img/newsx.png</image><link>rtsp://94.75.250.53:80/live136/newsx3</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>NewsX </name><type>News Channel</type><language>English</language><image>http://www.yupptv.com/img/newsx.png</image><link>rtsp://94.75.250.53:80/live136/newsx1</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>YupptvLive</name><type>Others Channel</type><language>English</language><image>http://www.yupptv.com/img/yupptv_iphone.png</image><link>rtsp://94.75.250.53:80/live136/kalaignar6002</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>YupptvLive</name><type>Others Channel</type><language>English</language><image>http://www.yupptv.com/img/yupptv_iphone.png</image><link>rtsp://94.75.250.53:80/live136/kalaignar6002</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>IndiaTV </name><type>News Channel</type><language>Hindi</language><image>http://www.yupptv.com/img/indiatv.png</image><link>rtsp://94.75.250.53:80/live136/indiatv1</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>IndiaTV </name><type>News Channel</type><language>Hindi</language><image>http://www.yupptv.com/img/indiatv.png</image><link>rtsp://94.75.250.53:80/live136/indiatv2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>IndiaTV </name><type>News Channel</type><language>Hindi</language><image>http://www.yupptv.com/img/indiatv.png</image><link>rtsp://94.75.250.53:80/live136/indiatv3</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Sahara Samay</name><type>News Channel</type><language>Hindi</language><image>http://www.yupptv.com/img/75x50_sahara_samay.png</image><link>rtsp://94.75.250.53:80/live136/saharasamay1</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Sahara Samay</name><type>News Channel</type><language>Hindi</language><image>http://www.yupptv.com/img/75x50_sahara_samay.png</image><link>rtsp://94.75.250.53:80/live136/saharasamay2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Sahara Samay</name><type>News Channel</type><language>Hindi</language><image>http://www.yupptv.com/img/75x50_sahara_samay.png</image><link>rtsp://94.75.250.53:80/live136/saharasamay3</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>ETV2</name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/etv2.png</image><link>rtsp://94.75.250.53:80/live136/etv21</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>ETV2</name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/etv2.png</image><link>rtsp://94.75.250.53:80/live136/etv22</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>ETV2</name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/etv2.png</image><link>rtsp://94.75.250.53:80/live136/etv23</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>HMTV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/HMTV.png</image><link>rtsp://94.75.250.53:80/rtplive/hmtvlow.sdp</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Maa Music</name><type>Music Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/maamusic.png</image><link>rtsp://94.75.250.53:80/live/maamusic3</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Maa Music</name><type>Music Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/maamusic.png</image><link>rtsp://94.75.250.53:80/live/maamusic2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Maa Music</name><type>Music Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/maamusic.png</image><link>rtsp://94.75.250.53:80/rtplive/maamusiclow.sdp</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>NTV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/ntv.png</image><link>rtsp://94.75.250.53:80/live136/ntv1</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>NTV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/ntv.png</image><link>rtsp://94.75.250.53:80/live136/ntv2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>NTV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/ntv.png</image><link>rtsp://94.75.250.53:80/live136/ntv3</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Raj News </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/rajnews.png</image><link>rtsp://94.75.250.53:80/live136/744_2CP47819PO1</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Raj News </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/rajnews.png</image><link>rtsp://94.75.250.53:80/live136/744_2CP47819PO2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Raj News </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/rajnews.png</image><link>rtsp://94.75.250.53:80/live136/744_2CP47819PO3</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>S V B C </name><type>Spiritual Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/live_svbc.png</image><link>rtsp://94.75.250.53/live/svbc3</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>S V B C </name><type>Spiritual Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/live_svbc.png</image><link>rtsp://94.75.250.220/rtplive/svbclow</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Sakshi TV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/Sakshi.png</image><link>rtsp://94.75.250.53/live136/sakshi1</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Sakshi TV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/Sakshi.png</image><link>rtsp://94.75.250.53/live136/sakshi2</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>Sakshi TV </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/Sakshi.png</image><link>rtsp://94.75.250.53:80/live136/sakshi3</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel><channel><name>StudioN </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/Studion_live.png</image><link>rtsp://94.75.250.220:1935/live/studion3</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>StudioN </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/Studion_live.png</image><link>rtsp://94.75.250.53:80/rtplive/studionlow.sdp</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>TV5 </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/tv5.png</image><link>rtsp://94.75.250.53:80/live136/tv51</link><bandwidth>High</bandwidth><cellnapid>16</cellnapid></channel><channel><name>TV5 </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/tv5.png</image><link>rtsp://94.75.250.53:80/live136/tv52</link><bandwidth>Medium</bandwidth><cellnapid>16</cellnapid></channel><channel><name>TV5 </name><type>News Channel</type><language>Telugu</language><image>http://www.yupptv.com/img/tv5.png</image><link>rtsp://94.75.250.53:80/live136/tv53</link><bandwidth>Low</bandwidth><cellnapid>16</cellnapid></channel></root>


    Please tell me How to i tried the above i.e Iam getting a blank screen please help me.URGENT
    Last edited by srk2011; 2011-04-27 at 16:24. Reason: I want to modify

Similar Threads

  1. Symbian QT Http POST with xml parsing
    By nikolaosnikolidakis in forum Qt
    Replies: 2
    Last Post: 2010-09-28, 11:31
  2. Replies: 12
    Last Post: 2010-03-21, 19:25
  3. hi XML Parsing in Symbian
    By 22abhinav82 in forum Symbian
    Replies: 2
    Last Post: 2006-06-11, 09:21
  4. Series 60 SDK 1.0 for Symbian OS, xml parsing
    By alokkumarsingh in forum Symbian
    Replies: 0
    Last Post: 2004-03-19, 06:53
  5. Replies: 0
    Last Post: 2003-12-15, 11:32

Posting Permissions

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