I am writing a Java program which will deminify any HTML/XML file from a single line to multiple lines (structured way). The method is simple. I am using a regex to split the single string into multiple strings and append a new line (\n) to each of those substring. BUT the program is not able to split my single string at all. Could any1 help me with this? Below is my program:
package Deminifier;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
public class Deminifier {
public static void main(String[] args) {
Deminifier demo = new Deminifier ();
demo.execute();
}
public void execute(){
BufferedReader br = null;
String currentLine;
try {
br = new BufferedReader(new FileReader("myfile.txt"));
while((currentLine = br.readLine())!= null){
System.out.println("Input text is as follows:");
System.out.println(currentLine);
Deminifier demo = new Deminifier();
System.out.println("Output Formatted text is as follows:");
demo.toDeminify(currentLine);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void toDeminify(String currentLine) {
String lineToParse = currentLine;
String returnString =null;
String[] splitString = (lineToParse.split("</([A-Z][A-Z0-9_]*)\b[^>]*>"));
System.out.println("Number of lines:"+splitString.length);
for (String s : splitString) {
System.out.println(s+"\n");
}
}
}
Can anyone help me in this matter? why is my String array "split String" returning just "1" array element? I have tried the regex expression and it works in one of my application (is able to identify all end tags).