2

I am reading a html file using an inputstream from a java servlet. But the contents of the original and the read one are in a different format although when displayed in a web browser they are the same. These are the two links for the html files after reading output http://www.fileflyer.com/view/gQREGAe orginal output http://www.fileflyer.com/view/mWXHVAE Is there a way to get the original html when reading? why is this happening? my java code is as follows;

InputStreamReader isr = new InputStreamReader(inputStream);
     BufferedReader br = new BufferedReader(isr);
     String line = null;
     while ( (line = br.readLine()) != null)
     {
      System.out.println(line);
}

Any help would be greatly appreciated!!

Thank you, rana.

3
  • what do you mean by different format? Commented Dec 22, 2010 at 5:38
  • html code is different. not the output from browser. Commented Dec 22, 2010 at 5:49
  • 3
    could you paste the code in somethin like pastie.org or pastebin.com. I'm not willing to download random files ;) Commented Dec 22, 2010 at 8:32

2 Answers 2

3

The one in different format (the one named extracted.html) is clearly generated by Microsoft Word.

<html xmlns:v="urn:schemas-microsoft-com:vml"
      xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:w="urn:schemas-microsoft-com:office:word"
      xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
      xmlns="http://www.w3.org/TR/REC-html40">

Your problem is more in the source of the InputStream, not in the Java or Servlet side. They do for sure not randomly change the content of the InputStream without your intervention.

You seem to be using MS Word as a HTML editor, you should not do that, there it is not for. Rather use a textbased editor like Notepad, Notepad++, Editplus, etc for HTML editing.

Sign up to request clarification or add additional context in comments.

Comments

0

I have seen both the html files. The extracted.html obviously has more tags/comments/css info that you doesn't seem to be interested. So, the only option you are left with is to use 1 of the below parsers and remove the unnecessary nodes/attributes you doesn't require (or just extract what you need)

  1. Mozilla html parser
  2. HTML Parser

1 Comment

hi, I have added an attribute named "template" to the original html code. but it is not represented in the output. do you know why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.