May 11, 2009 at 5:33 PM
Hi Friend,
To parse HTML file,try the following code:
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;
public class ParseHTML extends HTMLEditorKit.ParserCallback {
public void handleText(char[] data, int pos){
System.out.println(new String(data));
}
public void handleStartTag(HTML.Tag tag, MutableAttributeSet att, int pos){
System.out.println("Start tag: " + tag);
}
public void handleEndTag(HTML.Tag tag, int pos){
System.out.println("End tag: " + tag);
}
public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet att, int pos){
if (tag == HTML.Tag.META){
String name1=(String)att.getAttribute(HTML.Attribute.NAME);
if (name1 != null){
System.out.println("META name1: " + name1);
}
String content1 = (String)att.getAttribute(HTML.Attribute.CONTENT);
if (content1 != null){
System.out.println("META content1: " + content1);
}
}
}
public static void main(String argv[]) {
try {
Reader read = new FileReader("a.html");
ParserDelegator parser = new ParserDelegator();
HTMLEditorKit.ParserCallback callback = new ParseHTML();
parser.parse(read, callback, false);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
But first of all you need to create a html file.
Thanks
Related Tutorials/Questions & Answers:
html parsing in java and display in swinghtml parsing in
java and display in swing dear rose indians I am... HMTL pages in swing window forms to display
html contents i am using JEditorPane control.
Html contents is being is feteched from a local disc but links
java html parsing - Development processjava html parsing i want parse a
html page and get all the tags... need to build a general tree by
parsing the
html page so any one can help me...
HTML file,try the following code:
import java.io.*;
import javax.swing.
Advertisements
Html Parsing Extracting ContentHtml Parsing Extracting Content Hello
i need to parse
html and search for a string and get its attributes.For example 'xxx' is my search string. i search
html page and find xxx css attributes.Java,php,javascript is okey
thank
Parsing date in JavaParsing date in Java How can i parse the date in
Java in a simple format..?
SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy
java parsing of data typesjava parsing of data types Why its not works?
char ch; String s=*
ch=Character.parseChar(s)
program:
char op;
DataInputStream dis=new DataInputStream(System.in);
System.out.print("Enter operator (+,-,*,/,%): ");
op
Parsing a pharase - Java BeginnersParsing a pharase How do parse a sentence or pharse from a given passage??
Thank you in advance, plz help. it can be done in many ways some of them are
String.split methods
StringTokenizer and StreamTokenizer
java with xml parsing - Java Beginnersjava with xml parsing Hi,
I need the sample code for
parsing complex data xml file with
java code.
Example product,category,subcategory these type of xml files and parse using
java.
Please send the code immediately its very
XML parsing using Java - XMLXML
parsing using Java I'm trying to parse a big XML file in
JAVA.
The goal is like i will take console input from user until "Coverage" in element "MIRate"(THE XML code is below).once he enters coverage rate I need
java with xml parsing - Java Beginnersjava with xml parsing Hi,
I need the sample code for
parsing complex data xml file with
java code.
Example product,category,subcategory these type of xml files and parse using
java.
Please send the code immediately its very
java program for string tokenzing and parsingjava program for string tokenzing and parsing String s="height=128 weight=22 gender=male";
i need to convert this into height="128" weight="22" gender="male"
normally if we print "hello" means we use System.out.println("\"Hello
java program for string tokenzing and parsingjava program for string tokenzing and parsing String s="height=128 weight=22 gender=male";
i need to convert this into height="128" weight="22" gender="male"
normally if we print "hello" means we use System.out.println("\"Hello
java with htmljava with html actually we use
html code in the
java programs........ why we are using like
please tell me the reason..
please reply me soon
parsing XML file to get java object - XMLparsing XML file to get
java object Hello,
I'm facing a problem in
parsing XML file to get the
java object.
I've tried to retrieve data from XML file using SAX parser.
my XML file structure is the following
JAVA with HTMLJAVA with HTML Hello
I want an
JAVA example that would convert any UNICODE character OR STRING into its Equivalent
HTML Numeric[ASCII] values...
Like for character
?
it's equivalent value is
آ
like all the other
Question about parsing XML document with DOM in JAVA.Question about
parsing XML document with DOM in
JAVA. Hi, I need to parse a XML file witch has info about classes. So i have for each class to have its methods and for each method to get its parameters. I'm trying to do
java htmljava html program for jsp
--Select...-Type" content="text/
html; charset=UTF-8">
<title>JSP Page<...;
<meta http-equiv="Content-Type" content="text/
html; charset
Java to html - Java Beginners, i need help for writing the results from the
java application to the
html file... in
java to write data as
html content.
So write ur data with PrintWriter...
Java to html
Hi ,
I have to compare two text files, and put
JAVA N HTML - JavaMailJAVA N HTML How to use
HTML's mailto tag in a
java application...,
You can use mailto tag in
Java Servlets like this:
import java.io....,IOException{
response.setContentType("text/
html");
PrintWriter pw
HtmlHtml in the web page if judge select the age and category then automatically under that conditions the details will be display in the form of grid
give me that code in
html and
java HTMLHTML What is Semantic
HTML? What are the reasons for validating a
HTML HTMLHTML What is Semantic
HTML? What are the reasons for validating a
HTML HTMLHTML What is SPAN in
HTML HtmlHtml i am select the dateofbirth through the
html browser.but it can not save into the sql server 2008 database.any special code required to store the date in database by using
java servlets
Java to extract info to HTMLJava to extract info to HTML I need to write a
java program..., into
HTML format. I started by creating string instance variables for each... wrong?
I am in an intro course to
java so my knowledge of the language
HTMLHTML What is
HTML? What is a Hypertext link
HTMLHTML What is
HTML? What is a Hypertext link
HtmlHtml What is
HTML? What is a Hypertext link
HTMLHTML What is BODY in
HTML document
htmlhtml diffrence between
html and xml
htmlhtml How to add the calendar in
html code
HTML the file give me the code for this in
html and
java...HTML in
html how can we can upload the file
<tr>
<td><strong>Video of the work:</strong>
<td><b>
htmladd a header in the
html page what we can do to add a header in the
html page
HTMLHTML What is a tag? How can we use MARQUEE in
HTML htmlhtml how to convert
html page into jsp page
HTMLHTML how can we give the unlimited size in the
html HTMLHTML How do we specify page breaks in
HTML htmlhtml i want a registration page in
html with good background
htmlhtml what we can do to add a header in the
html page
htmlhtml what we can do to add a header in the
html page