I have an Xml document of which parts need to be Hashed for signature.
To get xml subtree I use Namespace aware Document outdocp
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("/EDoc/Signature/Object/QualifyingProperties/SignedProperties");
Node spNode = (Node) expr.evaluate(outdocp, XPathConstants.NODE);
But the results spNode
children whose prefix is ds
are missing xmlds::ds namespace
Online tool xpather.com correctly adds this namespace
xpather.com
Tried setting
xpath.setNamespaceContext(new NamespaceContext() {
@Override
public String getNamespaceURI(String s) {
if (s.equals("ds")) {
return "http://www.w3.org/2000/09/xmldsig#";
} else if (s.equals("xades")) {
return "http://uri.etsi.org/01903/v1.3.2#";
} else if (s.equals("xades141")) {
return "http://uri.etsi.org/01903/v1.4.1#";
}
return XMLConstants.NULL_NS_URI;
}
@Override
public String getPrefix(String s) {
return null;
}
@Override
public Iterator<String> getPrefixes(String s) {
return null;
}
});
it didnt help
New contributor
happy yuan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.