0

I have to get an email's content (HTML format) and save it to a string which then should be parsed to get the required details and to prepare an XML output.

I am using JAMES and i want it to be done in Java. How can I dump the HTML page into a string? Do you think I won't get any problem with the double inverted commas, spaces, backward slash while parsing?

Now i am testing mailserver on my localsystem. I sent a mail from user1@localhost to user2@localhost in format HTML At the other end i want to convert the parse HTML page to create an XML document with the desired values ..

1
  • 1
    JAMES is a server, is it not? Do you want to do this as a mail client, or on the server-side when processing incoming mail? I'd also suggest that your question is far too broad to be usefully answered - it would help a lot if you posted the skeleton of the code you'll be using, perhaps with comment like String htmlStr = // convert FooMessageImpl to string here to show where you need the conversion to happen. Commented Mar 3, 2011 at 11:37

1 Answer 1

1

Can you try with that example. Dumps html page and writes that data into data.html file. From bellow code you can append result to StringBuffer and replace the html special chars.

public class UrlReadPageDemo {
  public static void main(String[] args) {
    try {
        URL url = new URL("http://example.com");

        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        BufferedWriter writer = new BufferedWriter(new FileWriter("data.html"));

        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
            writer.write(line);
            writer.newLine();
        }

        reader.close();
        writer.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }  catch (IOException e) {
        e.printStackTrace();
    }
}

}

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

Comments

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.