*
The moose likes HTML, CSS and JavaScript and the fly likes How to compute the count of html_tag each line? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to compute the count of html_tag each line?" Watch "How to compute the count of html_tag each line?" New topic
Author

How to compute the count of html_tag each line?

qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
Hello, everybody!
How to compute the count of html tag in one line?
source code as following


Thanks...qingwu<br />When I open my eyes,I see your pretty face.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Feb 19, 2003
Posts: 147
�<...>' 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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 60774
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Feb 19, 2003
Posts: 147
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

Joined: Jan 10, 2002
Posts: 60774
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to compute the count of html_tag each line?
 
Similar Threads
Forwarding the current page to previous page
Can you read this?
How can I have a TAB inside my JSP
List item disappears in Firefox
Absolute Position in IE