ews-java-api icon indicating copy to clipboard operation
ews-java-api copied to clipboard

how to get the text values of appointment.getBody() without HTML Tags?

Open kervin521 opened this issue 11 years ago • 4 comments

String content = appointment.getBody().toString();

thie conent contain the html tags,but I want to get only the text of body.

how to get the text values of the body without HTML Tags?

kervin521 avatar Aug 13 '15 09:08 kervin521

Parse it...

        String patternString = "(.*<body.*?>)(.*)(</body>.*)";
        Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
        String htmlStr = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><style type=\"text/css\" style=\"display:none\"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style></head><body dir=\"ltr\" style=\"font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;\"><p>Some notes<br></p></body></html>";
        Matcher matcher = pattern.matcher(htmlStr);
        String htmlContent = matcher.matches() ? matcher.group(2) : "";
        // html content
        System.out.println(htmlContent);
        // stripped html content
        System.out.println(htmlContent.replaceAll("<.*?>", ""));

robsilvia avatar Aug 14 '15 16:08 robsilvia

you can also use some third party as jsoup

serious6 avatar Aug 14 '15 20:08 serious6

whether or not provide only the text of body without html tags in future for EWS API?

kervin521 avatar Aug 18 '15 11:08 kervin521

Lets have this as enhancement

serious6 avatar Aug 18 '15 19:08 serious6