@Test public void testParseOnePartToHTML() throws IOException, SAXException, TikaException { String result = example.parseOnePartToHTML().trim(); assertNotContained("<html", result); assertNotContained("<head>", result); assertNotContained("<meta name=\"dc:creator\"", result); assertNotContained("<title>", result); assertNotContained("<body>", result); assertContains("<p class=\"header\"", result); assertContains("This is in the header", result); assertNotContained("<h1>Test Document", result); assertNotContained("<p>1 2 3", result); }
public String parseOnePartToHTML() throws IOException, SAXException, TikaException { XPathParser xhtmlParser = new XPathParser("xhtml", XHTMLContentHandler.XHTML); Matcher divContentMatcher = xhtmlParser.parse("/xhtml:html/xhtml:body/xhtml:div/descendant::node()"); ContentHandler handler = new MatchingContentHandler( new ToXMLContentHandler(), divContentMatcher); AutoDetectParser parser = new AutoDetectParser(); Metadata metadata = new Metadata(); try (InputStream stream = ContentHandlerExample.class.getResourceAsStream("test2.doc")) { parser.parse(stream, handler, metadata); return handler.toString(); } }
ContentHandlerExample { public String parseOnePartToHTML() throws IOException, SAXException, TikaException { XPathParser xhtmlParser = new XPathParser("xhtml", XHTMLContentHandler.XHTML); Matcher divContentMatcher = xhtmlParser.parse("/xhtml:html/xhtml:body/xhtml:div/descendant::node()"); ContentHandler handler = new MatchingContentHandler( new ToXMLContentHandler(), divContentMatcher); AutoDetectParser parser = new AutoDetectParser(); Metadata metadata = new Metadata(); try (InputStream stream = ContentHandlerExample.class.getResourceAsStream("test2.doc")) { parser.parse(stream, handler, metadata); return handler.toString(); } } }
ContentHandlerExample { public String parseOnePartToHTML() throws IOException, SAXException, TikaException { XPathParser xhtmlParser = new XPathParser("xhtml", XHTMLContentHandler.XHTML); Matcher divContentMatcher = xhtmlParser.parse("/xhtml:html/xhtml:body/xhtml:div/descendant::node()"); ContentHandler handler = new MatchingContentHandler( new ToXMLContentHandler(), divContentMatcher); AutoDetectParser parser = new AutoDetectParser(); Metadata metadata = new Metadata(); try (InputStream stream = ContentHandlerExample.class.getResourceAsStream("test2.doc")) { parser.parse(stream, handler, metadata); return handler.toString(); } }  }
ContentHandlerExample { public String parseOnePartToHTML() throws IOException, SAXException, TikaException { XPathParser xhtmlParser = new XPathParser("xhtml", XHTMLContentHandler.XHTML); Matcher divContentMatcher = xhtmlParser.parse("/xhtml:html/xhtml:body/xhtml:div/descendant::node()"); ContentHandler handler = new MatchingContentHandler( new ToXMLContentHandler(), divContentMatcher); AutoDetectParser parser = new AutoDetectParser(); Metadata metadata = new Metadata(); try (InputStream stream = ContentHandlerExample.class.getResourceAsStream("test2.doc")) { parser.parse(stream, handler, metadata); return handler.toString(); } }  String parseToPlainText(); String parseToHTML(); String parseBodyToHTML(); String parseOnePartToHTML(); List<String> parseToPlainTextChunks(); }
ContentHandlerExample { public String parseOnePartToHTML() throws IOException, SAXException, TikaException { XPathParser xhtmlParser = new XPathParser("xhtml", XHTMLContentHandler.XHTML); Matcher divContentMatcher = xhtmlParser.parse("/xhtml:html/xhtml:body/xhtml:div/descendant::node()"); ContentHandler handler = new MatchingContentHandler( new ToXMLContentHandler(), divContentMatcher); AutoDetectParser parser = new AutoDetectParser(); Metadata metadata = new Metadata(); try (InputStream stream = ContentHandlerExample.class.getResourceAsStream("test2.doc")) { parser.parse(stream, handler, metadata); return handler.toString(); } }  String parseToPlainText(); String parseToHTML(); String parseBodyToHTML(); String parseOnePartToHTML(); List<String> parseToPlainTextChunks();  }