8 Replies - 781 Views - Last Post: 13 July 2009 - 05:16 AM Rate Topic: -----

#1 Protocol-X  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-June 09

Parsing HTML source

Post icon  Posted 28 June 2009 - 12:11 PM

Hello all, I need to find the best approach to doing what i need which will be described below. This is Going to be used for a mobile platform that does not support java.awt.

I want to colorize the source code of web document file types aka. html php js css. ect.

the sdk for the mobile platform requires a special span to be made to display the text with different styles and color.

exp. setspan(mycolor.(00ff00, bold), int start, int end);

where the start is the position in the string where you want to start the span and end is where to end it so say..

String source_code = "<html> <title>mytitle</title> this is my web page <div id="myId" class="myClass"</html>"

setspan(mycolor.(00ff00, bold), int 0, int 5); would change the color and set the boldness of <html>

now the problem is i need to scan the entire string or inputstream and get the start and end position of every word in it.. any ideas on the best way to do so? or just the start position would be great i could find the end position easly.

this was what i have come up with but it does not count into consideration the need to know attribute names like class=" and id="
Does anyone know the best approach to this?

In the end run im looking for it to basically have all element tags color one and bold. all atrributes="" blue and all the ret black.

This is an example of waht im looking to accomplish.

Before:
<html> <title>mytitle</title> this is my web page <div id="myId" class="myClass"</html>"

After:
<html> <title> mytitle
</title> this is my web page

<div
id="myId" class="myClass"

></html>


Basically exactly what the [code/code] tags do where wi what i am looking to accomplish in the end run

	
	String source_code = "<html>   <title>mytitle</title>   this is my web page <div id="myId" class="myClass"</html>"
	
	String [] compareTo = myString.split(" ");
	int setIndex = 0;
	For (int i = 0; i <= myString.length(); i++) {
	   if (!compareTo[i].matches(" ") {
		  String myScan = myString.substring(setIndex);
		  int bGn = myScan.indexOf(compareTo[i]);
		  int eNd = bGn + compareTo[i].length();
	  
		  myInput.seSpan(#00ff00, TypeFace.BOLD, bGn, eNd));
		  
		  i++;
		  setIndex += compareTo[i].length();
	   }else {
		  i++;
		  setIndex += compareTo[i].length();
	   }
	   
	}

This post has been edited by Protocol-X: 28 June 2009 - 01:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Parsing HTML source

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Parsing HTML source

Posted 28 June 2009 - 12:36 PM

Don't post your question in the topic title it gets truncated
Was This Post Helpful? 0
  • +
  • -

#3 Protocol-X  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-June 09

Re: Parsing HTML source

Posted 28 June 2009 - 12:50 PM

View Postpbl, on 28 Jun, 2009 - 11:36 AM, said:

Don't post your question in the topic title it gets truncated

Uhm what am i supposed to put in the topic then? and i did not put my Question in the topic i put it in the description.

This post has been edited by Protocol-X: 28 June 2009 - 12:51 PM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Parsing HTML source

Posted 28 June 2009 - 07:53 PM

View PostProtocol-X, on 28 Jun, 2009 - 11:50 AM, said:

View Postpbl, on 28 Jun, 2009 - 11:36 AM, said:

Don't post your question in the topic title it gets truncated

Uhm what am i supposed to put in the topic then? and i did not put my Question in the topic i put it in the description.

An hint about what your question will be about :D
Was This Post Helpful? 0
  • +
  • -

#5 Protocol-X  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-June 09

Re: Parsing HTML source

Posted 29 June 2009 - 12:22 PM

View Postpbl, on 28 Jun, 2009 - 06:53 PM, said:

View PostProtocol-X, on 28 Jun, 2009 - 11:50 AM, said:

View Postpbl, on 28 Jun, 2009 - 11:36 AM, said:

Don't post your question in the topic title it gets truncated

Uhm what am i supposed to put in the topic then? and i did not put my Question in the topic i put it in the description.

An hint about what your question will be about :D



Thanks but in the future you should probably tells oemone in a personal message because now i will probably never get any help because people see 5 replies in here and wont bother to look
Was This Post Helpful? 0
  • +
  • -

#6 computerfox  Icon User is offline

  • straight vegetarian kid

Reputation: 50
  • View blog
  • Posts: 3,772
  • Joined: 29-January 09

Re: Parsing HTML source

Posted 29 June 2009 - 12:37 PM

that's not true. all he's saying is to put the correct things in the proper locations.

also, shouldn't this be in the Javascript or some web development forum?

for further information Javascript != JAVA :)

This post has been edited by computerfox: 29 June 2009 - 12:39 PM

Was This Post Helpful? 0
  • +
  • -

#7 TriggaMike  Icon User is offline

  • Using up all your 1's and 0's
  • member icon

Reputation: 85
  • View blog
  • Posts: 1,103
  • Joined: 26-September 08

Re: Parsing HTML source

Posted 29 June 2009 - 04:47 PM

I would try to write an algorithm that parses out each HTML tag, and then parses what's inside of that to alternately colour the attributes. I would maybe look at using an iterator. So have a parser that can pull out strings of like "<html>"
or "<div id="whatever" name="blah">" and then you can check what's inside of that string to then refine your colouring scheme.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Parsing HTML source

Posted 29 June 2009 - 04:56 PM

View PostProtocol-X, on 29 Jun, 2009 - 11:22 AM, said:

Thanks but in the future you should probably tells oemone in a personal message because now i will probably never get any help because people see 5 replies in here and wont bother to look

Not far from your post there is one with 50 replies for a question on what System.out.println() does..... you are still candidate for a few answers :)
Was This Post Helpful? 0
  • +
  • -

#9 Protocol-X  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-June 09

Re: Parsing HTML source

Posted 13 July 2009 - 05:16 AM

View Postcomputerfox, on 29 Jun, 2009 - 11:37 AM, said:

that's not true. all he's saying is to put the correct things in the proper locations.

also, shouldn't this be in the Javascript or some web development forum?

for further information Javascript != JAVA :)


I am not an idiot i know javascript is not java. If you actually read you will see this has no indication im referring to java scrip. Just because u glance and see html in an example you assume.

this is in this forum because this is for java not Javascript.

but i can see this forum is unwilling to help and is jsut as bad as the other one filled with people that rather comment about anything but the help someone is looking for

This post has been edited by Protocol-X: 13 July 2009 - 05:24 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1