Hi,
I am trying to take an xml
string, convert that into a document type to be used for a function that is expected to verify the validity of the contents of this xml string. However, after converting to a document type, the builder.parse() attribute doesn't seem to return any values at all, due to which the validation function is failing. Given below is a code snippet for this.
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
String xmlResponse = "<?xml version="1.0" encoding="UTF-8" standalone="no"?><AuthRes code="5ee2f1d4-4cd6-4996-abad-9a2bc64847a9" info="01a8e6dc0e0c7eb69fb2897d2065284f578bcdfd6e18000000" ret="y" txn="DefaultTXN"><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>K2NuXDP3eFgzglLeHCD6tpogEvs=</DigestValue></Reference></SignedInfo><SignatureValue>m8XsACzxcFPxHRGqkD8tBzKTLlo9azB2e+4+RJ2c4sVettq6QymcVN1BIx0PYfu/lUDxxNlGHsWjcODcrdWnSlYff/6k8sBaTTAkq8+RTATokAOP9LRMgbszfCJLQx1Or+p8EUaeI5J+jEHe+pGFh6b/lsttX6p69lWeq6bp8oI=</SignatureValue></Signature></AuthRes>"
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document resDocument = builder.parse(new InputSource(new StringReader(responseBody)));
if(verify(resDocument)){
System.out.println("The Signature is certified properly");
}