public static Element detectHashedPostTree(Element signedElement,String postXPath){
  Element signedPostPart=signedElement;
  Node signedPostPartParent=signedPostPart.getParentNode();
  final XPathFactory factory=XPathFactory.newInstance();
  final XPath xpath=factory.newXPath();
  final Document ownerDocument=signedElement.getOwnerDocument();
  final NamespaceResolver nsr=new NamespaceResolver(ownerDocument);
  xpath.setNamespaceContext(nsr);
  XPathExpression expr=null;
  try {
    expr=xpath.compile(postXPath);
  }
 catch (  XPathExpressionException e1) {
    LOG.warn("No valid PostXPath: " + postXPath);
    return null;
  }
  NodeList nodes;
  while (signedPostPartParent != null && signedPostPartParent.getNodeType() == Node.ELEMENT_NODE) {
    try {
      nodes=(NodeList)expr.evaluate(signedPostPartParent,XPathConstants.NODESET);
    }
 catch (    XPathExpressionException e) {
      continue;
    }
    if (nodes.getLength() == 1) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Matched with postXPath from Element: " + signedPostPart.getNodeName());
      }
      break;
    }
    signedPostPart=(Element)signedPostPartParent;
    signedPostPartParent=signedPostPart.getParentNode();
  }
  return signedPostPart;
}

public static Element detectHashedPostTree ( Element signedElement , String postXPath ) { Element signedPostPart = signedElement ; Node signedPostPartParent = signedPostPart . getParentNode ( ) ; final XPathFactory factory = XPathFactory . newInstance ( ) ; final XPath xpath = factory . newXPath ( ) ; final Document ownerDocument = signedElement . getOwnerDocument ( ) ; final NamespaceResolver nsr = new NamespaceResolver ( ownerDocument ) ; xpath . setNamespaceContext ( nsr ) ; XPathExpression expr = null ; try { expr = xpath . compile ( postXPath ) ; } catch ( XPathExpressionException e1 ) { LOG . warn ( "No valid PostXPath: " + postXPath ) ; return null ; } NodeList nodes ; while ( signedPostPartParent != null && signedPostPartParent . getNodeType ( ) == Node . ELEMENT_NODE ) { try { nodes = ( NodeList ) expr . evaluate ( signedPostPartParent , XPathConstants . NODESET ) ; } catch ( XPathExpressionException e ) { continue ; } if ( nodes . getLength ( ) == 1 ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Matched with postXPath from Element: " + signedPostPart . getNodeName ( ) ) ; } break ; } signedPostPart = ( Element ) signedPostPartParent ; signedPostPartParent = signedPostPart . getParentNode ( ) ; } return signedPostPart ; }
detects the minimal elements protected by the postxpath . therefore , the postxpath is evaluated from the signedelement and step by step by its parents until the postxpath matches exactly one element . this one is returned .
