private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException { LinkedList<String> result = new LinkedList<>(); try { Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in)); XMLOutputter out = new XMLOutputter(); for (String xp : xpaths) { XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content()); for (Content node : xpath.evaluate(doc)) { if(node instanceof Element) { result.add(out.outputString((Element) node)); } else if(node instanceof Text) { result.add(out.outputString((Text) node)); } } } return result; } catch (JDOMException xpe) { throw new IllegalArgumentException("error while processing xpath expressions: '" + xpaths + "'", xpe); } }
private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException { LinkedList<String> result = new LinkedList<>(); try { Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in)); XMLOutputter out = new XMLOutputter(); for (String xp : xpaths) { XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content()); for (Content node : xpath.evaluate(doc)) { if(node instanceof Element) { result.add(out.outputString((Element) node)); } else if(node instanceof Text) { result.add(out.outputString((Text) node)); } } } return result; } catch (JDOMException xpe) { throw new IllegalArgumentException("error while processing xpath expressions: '" + xpaths + "'", xpe); } }