use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRRestAPIClassifications method writeXML.
/**
* Output xml
* @param eRoot - the root element
* @param lang - the language which should be filtered or null for no filter
* @return a string representation of the XML
* @throws IOException
*/
private static String writeXML(Element eRoot, String lang) throws IOException {
StringWriter sw = new StringWriter();
if (lang != null) {
// <label xml:lang="en" text="part" />
XPathExpression<Element> xpE = XPathFactory.instance().compile("//label[@xml:lang!='" + lang + "']", Filters.element(), null, Namespace.XML_NAMESPACE);
for (Element e : xpE.evaluate(eRoot)) {
e.getParentElement().removeContent(e);
}
}
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
Document docOut = new Document(eRoot.detach());
xout.output(docOut, sw);
return sw.toString();
}
Aggregations