Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

how to read text from html data?

Hi,

I want to display text from html data.like:

<html>

<body>

Display text from here

</body>

</html>

 

 

I want to display the text which is between body tag.How to do it? I am getting the whole html content.Please help me!!

Rujuta Trivedi
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to read text from html data?

Check the xmldemo sample shipped with the JDE.

 

Regards

Bikas

Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

Re: how to read text from html data?

its xml format and i want to display from html file

Rujuta Trivedi
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to read text from html data?

Sorry didn't clearly noticed the html previously.

About html, I think  you have to parse that manually, painful task though.

 

Regards

Bikas

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: how to read text from html data?

The hardest part is thunking up HTML to XHTML, depending on your task this might be as simple as changing constructs like <br> to <br /> for example, or it might entail more work.

 

Once that's done, you can use an XML parser like DOM or SAX (both provided in the base BB APIs) on the XHTML, and it becomes a trivial task once you've understood how these parsers work.

Developer
Posts: 101
Registered: ‎07-21-2009
My Device: Not Specified

Re: how to read text from html data?

just an idea - How about passing the URL directly to Browser Field??

Highlighted
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: how to read text from html data?

[ Edited ]

If you are looking for a browserfield type of thing for 5.0 below version this link  might help you out.

 

Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: how to read text from html data?

Hi,

 

Try this logic, suppose if your html data is in string then you can extaract your required string in the following way.

 

public String extractStringFromHtml(String htmlData)
{
String str = "";
char[] temp=htmlData.toCharArray();
  for (int i = 0; i < temp.length; i++) 
  {
   if (temp[i] == '>' && (temp[i + 1] != '<' && temp[i+1]!='/'))
   {
    i = i + 1;
    while (temp[i] != '<') 
    {
     str += temp[i];
     i++;
    }
    break;
   }
  }
return str;
  }

 I am not sure , you may need to change as per your requirements.

this is only basic idea.

 

Thanks.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to read text from html data?

Some links to similar Threads with other solutions are here:

http://supportforums.blackberry.com/t5/Java-Development/Error/m-p/1276943#M171734

Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: how to read text from html data?

[ Edited ]

In the following link I put some code it must help you.

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/executeScript-not-work-help-me-p...

 

 

In that you use browserField.requestContent("local:///index.html")

at....

if(field==click)

{

//write the above hilighted statement. enough;

}

===========================================================================

feel free to press the like button on the right side to thank the user that helped you.



=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.