Search HTML Formats in Java
Native and high performance HTML file search using Java APIs, without the use of any software like Microsoft or Adobe PDF.
How to Search HTML File Using Java
In order to search HTML file, we’ll use
API which is a feature-rich, powerful and easy to use Search API for Java platform. You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>version of aspose-words API</version>
<classifier>jdk17</classifier>
</dependency>
Steps to Search HTML Files in Java
Developers can easily integrate code with just few lines as listed.
- Load HTML file by instantiating Document Class object.
- Instantiate FindReplaceOptions.
- Use Pattern.compile() method to define a regex pattern
- Use getRange().replace method to find and replace
- Save HTML file.
System Requirements
Before integrating the code, make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.Words for Java directly from Maven .
Search HTML Files - Java
// Load HTML file
Document html = new Document("sourceFile.html");
// Find and replace similar pattern words in the file
FindReplaceOptions options = new FindReplaceOptions();
html.getRange().replace(Pattern.compile("[B|S|M]ad"), "[replaced]", options);
// Save the HTML file
html.save("output.html");
Online HTML Search Live Demos
HTML What is HTML File Format
HTML (Hyper Text Markup Language) is the extension for web pages created for display in browsers. Known as language of the web, HTML has evolved with requirements of new information requirements to be displayed as part of web pages. The latest variant is known as HTML 5 that gives a lot of flexibility for working with the language. HTML pages are either received from server, where these are hosted, or can be loaded from local system as well. Each HTML page is made up of HTML elements such as forms, text, images, animations, links, etc. These elements are represented by tags such as img, a, p and several others where each tag has start and end. It can also embed applications written in scripting languages such as JavaScript and Style Sheets (CSS) for overall layout representation.
Read MoreOther Supported Search Documents
Using Java, one can also search other files including.