Your Digital Media Has Never Looked So Good

 
RENJITHVR4
Topic Author
Posts: 13
Joined: Sat Jul 09, 2016 4:17 am

How to parse HTML tags by using Brightscript?

Fri Oct 07, 2016 2:27 am

From API , we have some text with HTML tags. Actually, it is privacy policy content. So is it possible to show privacy policy content without HTML tags? But we want the Right style. Like font size and weight. Is it possible to convert HTML tags to relevant format for this? Please suggest me the best way.

For example 

<ol>\r\n\t<li>We use Personal Data to allow you to participate in the features on the Site, to process your registration, and to provide you with other requested content related to our content and other offerings. Click here to learn more&nbsp;</li></ol>
 
venkatareddy
Posts: 21
Joined: Thu Jun 29, 2017 4:56 am

Re: How to parse HTML tags by using Brightscript?

Mon Oct 29, 2018 5:08 am

Hi 
I am also looking for same issue, if you got any solution for this. Please give me an update. Thanks in advance, hope to get response from you.
 
User avatar
speechles
Posts: 71
Joined: Thu Aug 06, 2015 11:15 pm

Re: How to parse HTML tags by using Brightscript?

Mon Oct 29, 2018 10:13 am

Brightscript Debugger> html = "<tag>hi there<another tag/><tag2> <TAG3>MORE</tag3>"

Brightscript Debugger> ? html
<tag>hi there<another tag/><tag2> <TAG3>MORE</tag3>

Brightscript Debugger> r = CreateObject("roRegex", "<.*?>", "") : ? r.ReplaceAll(html, "")
hi there MORE

Brightscript Debugger> html = "\r\n\tHELLO \r\r\rHOW ARE YOU?"

Brightscript Debugger> ? html
\r\n\tHELLO \r\r\rHOW ARE YOU?

Brightscript Debugger> r = CreateObject("roRegex", "(\\r|\\t|\\v|\\n)", "") : ? r.ReplaceAll(html, "")
HELLO HOW ARE YOU?


Brightscript Debugger> html = "<ol>\r\n\t<li>We use Personal Data to allow you to participate in the features on the Site, to process your registration, and to provide you with other requested content related to our content and other offerings. Click here to learn more&nbsp;</li></ol>"

' strip html tags
Brightscript Debugger> r = CreateObject("roRegex", "<.*?>", "") : html = r.ReplaceAll(html, "")

' strip carriage return, tab, vertical tab, newline
Brightscript Debugger> r = CreateObject("roRegex", "(\\r|\\t|\\v|\\n)", "") : html = r.ReplaceAll(html, "")

Brightscript Debugger> ?html
We use Personal Data to allow you to participate in the features on the Site, to process your registration, and to provide you with other requested content related to our content and other offerings. Click here to learn more&nbsp;

' strip non breaking space entity
Brightscript Debugger> r = CreateObject("roRegex", "&nbsp;", "") : ? r.ReplaceAll(html, "")
We use Personal Data to allow you to participate in the features on the Site, to process your registration, and to provide you with other requested content related to our content and other offerings. Click here to learn more
 
User avatar
RokuNB
Posts: 446
Joined: Fri Mar 31, 2017 2:22 pm

Re: How to parse HTML tags by using Brightscript?

Thu Nov 01, 2018 2:59 pm

don't use roRegEx when simple .replace() would do; the latter is faster.
roXmlElement may be of help, if the html in question is well-formed from the point of view of XML.
 
User avatar
speechles
Posts: 71
Joined: Thu Aug 06, 2015 11:15 pm

Re: How to parse HTML tags by using Brightscript?

Thu Nov 01, 2018 3:26 pm

replace doesn't do glob or grouping does it?

So would still need regex to strip the html tags and possibly the grouped \r \n \t \v. You are right though, the last part where it strips off the &nbsp; could've been replace.
 
User avatar
RokuNB
Posts: 446
Joined: Fri Mar 31, 2017 2:22 pm

Re: How to parse HTML tags by using Brightscript?

Fri Nov 02, 2018 2:19 pm

i doubt actual string would have backspace literals, that's neither here (html) nor there (c source) encoding. In Roku-speak, \r\n\t would have been chr(13)+chr(10)+chr(8)
 
User avatar
speechles
Posts: 71
Joined: Thu Aug 06, 2015 11:15 pm

Re: How to parse HTML tags by using Brightscript?

Fri Nov 02, 2018 3:23 pm

chr(8) is backspace. chr(9) = \t = horizontal tab and chr(11) = \v = vertical tab. You silly rabbit.

Brightscript Debugger> ? "no"+chr(8)+chr(8)+"yes"
yes
 
User avatar
RokuNB
Posts: 446
Joined: Fri Mar 31, 2017 2:22 pm

Re: How to parse HTML tags by using Brightscript?

Sat Nov 03, 2018 3:15 pm

speechles wrote:
chr(8) is backspace. chr(9) = \t = horizontal tab and chr(11) = \v = vertical tab. You silly rabbit.

i stand corrected.

Who is online

Users browsing this forum: No registered users and 1 guest