Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compute the count of html_tag each line?

 
qingwu wang
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everybody!
How to compute the count of html tag in one line?
source code as following
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean...You want the number of html tags in the page or inside a certain element.

Look into getElementsByTagName with *

Eric
 
qingwu wang
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
�<...>' or <.../> as one tag.
for example, '<html>' count one and <head><title> count two,
'<h1><color></color></h1>' count four.
Thanks a lot for any help.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript does not know how the page is formatted so it has no clue. You can try reading nodes in the dom and see what type of node it is, other than that it is up to you to parse text.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth do you need to do such a weird thing? Perhaps if we knew why you were trying to do this, we could pose alternatives.
 
Paul Clapham
Sheriff
Pie
Posts: 20716
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by qingwu wang:
'<h1><color></color></h1>' count four.
And I expect an empty element tag like '<br/>' counts as one? I too would like to know where this strange requirement came from.
 
qingwu wang
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to compute 'text density' and filter useless line.
I have formated it to dom style and perhaps need regexp or others.
I don't confirm it.

'text density':some one line words divid tag count of current line.
if some one line has too many tags, We think it is useless.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by qingwu wang:
if some one line has too many tags, We think it is useless.
Huh? How do you figure that? Are you just trying to figure out a way to "pretty print" the code? Most IDEs will do that for you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic