how html tags are extracted using java?

Ads
 

how html tags are extracted using java?

I would like to need the java code for extracting html tags.

View Answers

August 28, 2012 at 4:27 PM

Here is a java example that extract a tag from a line of HTML using the Pattern and Matcher classes.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExtractContentFromHTMLTag
{
  public static void main(String[] args)
  {
    String stringToSearch = "<p>Hello <h1>Welcome To Roseindia</h1> ...</p>";

    Pattern p = Pattern.compile("<h1>(\\S+)</h1>");
    Matcher m = p.matcher(stringToSearch);

    if (m.find()){
      String codeGroup = m.group(1);
      System.out.format("'%s'\n", codeGroup);
    }
  }
}

August 28, 2012 at 4:33 PM

Modify the above code.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExtractContentFromHTMLTag
{
  public static void main(String[] args)
  {
    String stringToSearch = "<p>Hello <h1>WelcomeToRoseindia</h1> ..</p>";

    Pattern p = Pattern.compile("<h1>(\\S+)</h1>");
    Matcher m = p.matcher(stringToSearch);

    if (m.find())
    {
      String codeGroup = m.group(1);

      System.out.format("'%s'\n", codeGroup);
    }

  }
}

Ads









Related Tutorials/Questions & Answers:
how html tags are extracted using java?
how html tags are extracted using java?
Advertisements
html tags
Java2
how to print HTML using javascript or Jquery
Using Core Tags, Html Tags
how to write a jsp form using html
how to insert data in database using html+jsp
How to export data from html to excel sheet by using java
how to validate the telephone number without using jquery in html with javascript
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java
how to convert doc file into html using java swing
How to give value for select in HTML dynamically using javascript
how to update values of a html form into an excel table using java servlets?
how to load values of html form into an excel table using java servlet?
How to Validate dynamically created text box in HTML using Javascript
how to save html form data into .csv file using only jsp.
Javah
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
ModuleNotFoundError: No module named 'djangocms-html-tags'
ModuleNotFoundError: No module named 'djangocms-html-tags'
ModuleNotFoundError: No module named 'lektor-strip-html-tags'
Version of commons-jelly-tags-html>commons-jelly-tags-html dependency
how to retrieve image from mysql database using java and show it in HTML img tag ?
How to play FLV video files on Ipad using HTML code or javascript code?
Hi how to transfer table data from html page to excel sheet by using javascript .
Style Tags Used in HTML
Error in using jstl tags
how to scrape the data from one website another website using html dom parsing in php
How to get the text from textarea in HTML and store it in database using javascript and jsp

Ads