how html tags are extracted using java?

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
Using Core Tags, Html Tags
how to print HTML using javascript or Jquery
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
Javah
How to export data from html file to excel sheet by using java
how to convert doc file into html using java swing
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 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 give value for select in HTML dynamically using javascript
Style Tags Used in HTML
How to Validate dynamically created text box in HTML using Javascript
Artifacts of commons-jelly-tags-html
how to save html form data into .csv file using only jsp.
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
Error in using jstl tags
Maven Dependency commons-jelly-tags-html >> 20040902.072530
Version of beehive>beehive-netui-tags-html dependency
Version of controlhaus>beehive-netui-tags-html dependency
how to retrieve image from mysql database using java and show it in HTML img tag ?

Ads