Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kartik
java html parsing
2 Answer(s)      5 years and 6 months ago
Posted in : Development process



Advertisement
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
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
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
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 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
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
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
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 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 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
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
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
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 Client Application
Java HTML Client Application  Java HTML Client Application
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
xml to html via java
xml to html via java  how to read xml into html using java code
xml parsing
xml parsing  my task is when i wll give java file to a program that program interpret that file separate each and every keywords and indentifiers and return the csv file that contains count of used keywords and idenfiers by using
html form - Java Beginners
html form  Hi
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
parsing xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
XML parsing to Mysql database
XML parsing to Mysql database  Can someone please post the code for parsing an XML file into Mysql database using SAX
 

 

 

DMCA.com