kartik
java html parsing
2 Answer(s)      4 years ago
Posted in : Development process

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 Pages:
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.
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
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
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
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
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
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
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
where i can store in the database SEND ME THE CODE FOR THIS IN JAVA AND HTML
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
XML Parsing from php web server in J2ME
XML Parsing from php web server in J2ME  Hello Team, You gave some tips for XML parsing in java, i need some additional tips for xml parsing from php web server in j2me... Thanks and Regards Alagu
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
Exception during parsing a parameter from the form in JSP
Exception during parsing a parameter from the form in JSP  Exception during parsing params from a form? I get parameters from a html form. I parse the integer one in the JSP file, but I get exception. Is there anyway I can get
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 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 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  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
XML Parsing Error: mismatched tag. Expected: </br>. - JSP-Servlet
XML Parsing Error: mismatched tag. Expected: .  i had an error:"XML Parsing Error: mismatched tag. Expected: ." when uploading and writing them.../jsp/jdo-mparsing-xml.shtml http://www.roseindia.net/jsp/java-beans.shtml
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
Handling Errors While Parsing an XML File
parsing an XML document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used... Handling Errors While Parsing an XML File   
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
html tags
html tags  html tags   Java Struts HTML Tags
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
html form - Java Beginners
html form  Hi
xml to html via java
xml to html via java  how to read xml into html using java code
how to save web pages in a partcular document in html format using java.. - Java Beginners
how to save web pages in a partcular document in html format using java..  i have to save a particular web page in a folder in html format using java... save the web page in a folder and then will parse the page. the parsing part
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
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 form - Java Beginners
html form  Hi, I wnt to design a form with more than one action in submit button.thanks. regards, sakthi  Hi friend, You specify your main requirement of form with more then one action. Thanks
HTML form - Java Beginners
HTML form   Hi, thank u for fast reply. I have two forms (form1 and form 2)with several fields in html. When i click the submit button, it validates all fields then moves to form2. i have a problem with form navigation. i
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
On HTML - Java Beginners
On HTML  Hi, This is Dedeepya.Most of you are aware of Yahoo Registration page(HTML).I have few doubts regarding that. 1.Username Text Box... to do this for each and every text box in my HTML page and also if the user
Formatting and Parsing a Number for a Locale
Formatting and Parsing a Number for a Locale In this section, you will learn..., number, or message from its internal representation into a string. Parsing... of the date, time, number, or message. Java has provide different classes
Formatting and Parsing a Time for a Locale
Formatting and Parsing a Time for a Locale In this section, you will learn how to format and parse a time for a locale. Java has provide several classes.... For formatting and parsing the time, here we have used DateFormat class
On HTML and JavaScript - Java Beginners
On HTML and JavaScript  Hi I have a SelectBox for ex i want to select a month from selectbox I want the default value of select box to be select but when user select the box for options then there should not be option called

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.