<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package pl.edu.mimuw.xml.rest;

import java.io.File;
import java.io.IOException;

import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

@Path("/xmls")
public class XPathService {
	private final static String basePath = "/home/patryk/rest_docs/";
	
	@GET
	@Produces("text/plain")
	public String getDocument(
			@MatrixParam("doc") String docPath,
			@MatrixParam("xpath") String expr
			)
					throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		Document doc = db.parse(new File(basePath + docPath));

		XPathFactory xpf = XPathFactory.newInstance();
		XPath xp = xpf.newXPath();
		String result = xp.evaluate(expr, doc);
		
		
		return result;
	}
}
</pre></body></html>