Java XPath Get getDigestValue(Node reference)

Here you can find the source of getDigestValue(Node reference)

Description

Returns the value of DigestValue node

License

BSD License

Parameter

Parameter Description
reference the Reference node

Exception

Parameter Description
XPathExpressionException on XPath evaluation error

Return

the value

Declaration

public static String getDigestValue(Node reference) throws XPathExpressionException 

Method Source Code

//package com.java2s;
/**/*from  w w  w.  j a  va  2 s .co m*/
 * Copyright 5AM Solutions Inc
 * Copyright SemanticBits LLC
 * Copyright AgileX Technologies, Inc
 * Copyright Ekagra Software Technologies Ltd
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/cacis/LICENSE.txt for details.
 */

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;

public class Main {
    /**
     * XPath expression to retrieve the digest value of a Reference element
     */
    public static final String GET_DIG_VAL_EXP = "*[local-name()='DigestValue']";

    /**
     * Returns the value of DigestValue node
     * 
     * @param reference the Reference node
     * @return the value
     * @throws XPathExpressionException on XPath evaluation error
     */
    public static String getDigestValue(Node reference) throws XPathExpressionException {
        return getNodeValue(reference, GET_DIG_VAL_EXP);
    }

    private static String getNodeValue(Node node, String expStr) throws XPathExpressionException {
        final XPathFactory fac = XPathFactory.newInstance();
        final XPath xpath = fac.newXPath();
        final XPathExpression exp = xpath.compile(expStr);
        final Node selected = (Node) exp.evaluate(node, XPathConstants.NODE);
        return selected.getTextContent();
    }
}

Related

  1. getCache()
  2. getCertificateFromKeyInfo(Node keyInfoNode)
  3. getCruxPagesXPath()
  4. getDefaultXPath()
  5. getDefaultXPathFactory()
  6. getElementByXpath(Element sourceRoot, String xpathExpress)
  7. getElementsByXPath(Element parent, String name)
  8. getElementXPath(Node elt)
  9. getExcelPath()