Example usage for javax.xml.xpath XPath evaluate

List of usage examples for javax.xml.xpath XPath evaluate

Introduction

In this page you can find the example usage for javax.xml.xpath XPath evaluate.

Prototype

public String evaluate(String expression, InputSource source) throws XPathExpressionException;

Source Link

Document

Evaluate an XPath expression in the context of the specified InputSource and return the result as a String .

Usage

From source file:org.apache.pdfbox.pdmodel.fdf.FDFAnnotationPolygon.java

private void initVertices(Element element) throws IOException, NumberFormatException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {/*from  ww w. j a v  a  2  s.c o  m*/
        String vertices = xpath.evaluate("vertices", element);
        if (vertices == null || vertices.isEmpty()) {
            throw new IOException("Error: missing element 'vertices'");
        }
        String[] verticesValues = vertices.split(",");
        float[] values = new float[verticesValues.length];
        for (int i = 0; i < verticesValues.length; i++) {
            values[i] = Float.parseFloat(verticesValues[i]);
        }
        setVertices(values);
    } catch (XPathExpressionException e) {
        LOG.debug("Error while evaluating XPath expression for polygon vertices");
    }
}