Exemplo n.º 1
0
  /**
   * Returns the number value of the first item selected by applying the wrapped XPath expression to
   * the given context.
   *
   * @param context the element to use as context for evaluating the XPath expression.
   * @return the number value of the first item selected by applying the wrapped XPath expression to
   *     the given context, <code>null</code> if no node was selected or the special value {@link
   *     java.lang.Double#NaN} (Not-a-Number) if the selected value can not be converted into a
   *     number value.
   * @throws JDOMException if the XPath expression is invalid or its evaluation on the specified
   *     context failed.
   */
  @Override
  public Number numberValueOf(Object context) throws JDOMException {
    try {
      navigator.setContext(context);

      return xPath.numberValueOf(context);
    } catch (JaxenException ex1) {
      throw new JDOMException(
          "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1);
    } finally {
      navigator.reset();
    }
  }
Exemplo n.º 2
0
  /**
   * Evaluates the wrapped XPath expression and returns the first entry in the list of selected
   * nodes (or atomics).
   *
   * @param context the node to use as context for evaluating the XPath expression.
   * @return the first selected item, which may be of types: {@link Element}, {@link Attribute},
   *     {@link Text}, {@link CDATA}, {@link Comment}, {@link ProcessingInstruction}, Boolean,
   *     Double, String, or <code>null</code> if no item was selected.
   * @throws JDOMException if the evaluation of the XPath expression on the specified context
   *     failed.
   */
  @Override
  public Object selectSingleNode(Object context) throws JDOMException {
    try {
      navigator.setContext(context);

      return unWrapNS(xPath.selectSingleNode(context));
    } catch (JaxenException ex1) {
      throw new JDOMException(
          "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1);
    } finally {
      navigator.reset();
    }
  }