Redact XHTML Formats in Java
Native and high performance XHTML document sensitive redaction information using Java APIs, without the use of any software like Microsoft or Adobe PDF.
How to Redact XHTML File Using Java
In order to redact XHTML file, we’ll use
API which is a feature-rich, powerful and easy to use redaction 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 Redact XHTML Files in Java
A basic document search and replace text in contents, comments or metadata can be done with just few lines of code. Redact sensitive information through search and replace text in contents, comments or metadata in Word documents.
- Instantiate Document class.
- Create FindReplaceOptions object.
- Set Pattern
- Use Replace method with relevant options.
- Save document.
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 .
Redact XHTML Files - Java
Document xhtml = new Document();
DocumentBuilder builder = new DocumentBuilder(xhtml);
builder.writeln("sad mad bad");
if(xhtml.getText().trim() == "sad mad bad"){
System.out.println("Strings are equal!");
}
// Replaces all occurrences of the words "sad" or "mad" to "bad".
FindReplaceOptions options = new FindReplaceOptions();
xhtml.getRange().replace(Pattern.compile("[s|m]ad"), "bad", options);
// Save the XHTML document.
xhtml.save(dataDir + "output.xhtml");
Online XHTML Redaction Live Demos
XHTML What is XHTML File Format
The XHTML is a text based file format with markup in the XML, using a reformulation of HTML 4.0. These files are well suited to be open or viewed in a web browser. XHTML was designed to be more structured, less scripting, generic; using all the existing facilities of XML and more device independent. XHTML provides a generally worthwhile set of elements and attributes, with extension options in combination with style sheets. The attributes are used from the metadata attributes collection. XHTML provides flexibility and accessibility by subordinating all HTML presentation elements to style sheets. Style sheets are more versatile than these presentational elements. Specifications for HTML 4.01, HTML5 and XHTML are being dynamically developed by the World Wide Web Consortium (W3C).
Read MoreOther Supported Redaction Documents
Using Java, one can easily redact different formats including.