java html parsing

java html parsing

View Answers

May 11, 2009 at 5:01 PM

Use class HTMLEditorKit in java

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 swing
html 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 process
java 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 Content
Html 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 Java
Parsing 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 types
java 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 Beginners
Parsing 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
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
java with xml parsing - Java Beginners
java 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
how to scrape the data from one website another website using html dom parsing in php
how to scrape the data from one website another website using html dom parsing in php  " how to scrape the data from one website another website using html dom parsing in php" i'm trying this one .please provide code for me
XML parsing using Java - XML
XML 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 Beginners
java 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 parsing
java 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 parsing
java 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 html
java 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 - XML
parsing 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 HTML
JAVA 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 HTML Client Application
Java HTML Client Application  Java HTML Client Application
java html
java 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 html
java html  program for jsp
java html
java html  program for jsp
java html
java html  program for jsp
java html
java html  program for jsp
xml to html via java
xml to html via java  how to read xml into html using java code
Java error reached end of file while parsing
Java error reached end of file while parsing       Java Error reached end... an error i.e java error reached end of file while parsing as the class closing braces
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
html form - Java Beginners
html form  Hi
Removing HTML from a Java String
Removing HTML from a Java String  Removing HTML from a Java String
JAVA N HTML - JavaMail
JAVA 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
Html
Html  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
HTML
HTML  What is Semantic HTML? What are the reasons for validating a HTML
HTML
HTML  What is Semantic HTML? What are the reasons for validating a HTML
HTML
HTML  What is SPAN in HTML
Html
Html  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 HTML
Java 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
HTML
HTML  What is HTML? What is a Hypertext link
HTML
HTML  What is HTML? What is a Hypertext link
Html
Html  What is HTML? What is a Hypertext link
HTML
HTML  What is BODY in HTML document
html
html  diffrence between html and xml
html
html  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>
html
add a header in the html page  what we can do to add a header in the html page
HTML
HTML  What is a tag? How can we use MARQUEE in HTML
html
html  how to convert html page into jsp page
HTML
HTML  how can we give the unlimited size in the html
HTML
HTML  How do we specify page breaks in HTML
html
html  i want a registration page in html with good background
html
html  what we can do to add a header in the html page
html
html  what we can do to add a header in the html page

Ads