I am trying to extract a subtree of an xml document which contains several namespaces
<?xml version=”1.0″ encoding=”UTF-8″?>
<EDoc><Msg></Msg><ds:Signature xmlns:ds=”http://www.w3.org/2000/09/xmldsig#” Id=”xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194″><ds:SignedInfo><ds:CanonicalizationMethod Algorithm=”http://www.w3.org/2001/10/xml-exc-c14n#”></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm=”http://www.w3.org/2001/04/xmldsig-more#rsa-sha256″></ds:SignatureMethod><ds:Reference Id=”xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194-ref0″ URI=””><ds:Transforms><ds:Transform Algorithm=”http://www.w3.org/2000/09/xmldsig#enveloped-signature”></ds:Transform><ds:Transform Algorithm=”http://www.w3.org/2001/10/xml-exc-c14n#”></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm=”http://www.w3.org/2001/04/xmlenc#sha256″></ds:DigestMethod><ds:DigestValue>aR2rk0u2+0j+j9/Ndj+eGMyQSwsTKYimF49V1DUGHLY=</ds:DigestValue></ds:Reference><ds:Reference Type=”http://uri.etsi.org/01903#SignedProperties” URI=”#xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194-signedprops”><ds:Transforms><ds:Transform Algorithm=”http://www.w3.org/2001/10/xml-exc-c14n#”></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm=”http://www.w3.org/2001/04/xmlenc#sha256″></ds:DigestMethod><ds:DigestValue>BEOuHSPUKFQBWP8QXZnHRYwC2O7saTNNTR3sDRdrVm4=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue Id=”xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194-sigvalue”>uH1J5rKZ3qs9d4a3GLZAvGvuTzR8fa0ioiyzzbXZGhUljT7o7DUeNxNRc3gqXuw4OdVhuDID6BNLG/FEzpZvyf7bK8p/RiPPQup+PqrHUPrgRpzhzFodLEGAckcxnsQx5VlJpuiXGYGYzX/Qy8FmQt7hYBstfkOvENs81qDl1DJSLpd5P4mkUcMFIjhXAR2tUByGb8sQn0we1y4YbUrbmf2pz49Lzrqju6/6z4BeVVyGnau5fOsRwhsVC6E0BozprF7+dk6hhm8jws/vAMr6eTVQa5uabeBx2NMPeO3LSDEyO7SvHBZFclrT1AU4OJNmr81aKrAV5GCOQgMBylWnnw==</ds:SignatureValue><ds:Object><ds:QualifyingPropertiesReference URI=”http://www.lb.lt/pki/crl/?/K0DLB7mSteWoTDKI/kV2Jsmfbk=”></ds:QualifyingPropertiesReference><xades:QualifyingProperties xmlns:xades=”http://uri.etsi.org/01903/v1.3.2#” xmlns:xades141=”http://uri.etsi.org/01903/v1.4.1#” Target=”#xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194″><xades:SignedProperties Id=”xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194-signedprops”><xades:SignedSignatureProperties><xades:SigningTime>2024-05-26T16:52:45+03:00</xades:SigningTime><xades:SigningCertificate><xades:Cert><xades:CertDigest><ds:DigestMethod Algorithm=”http://www.w3.org/2001/04/xmlenc#sha256″></ds:DigestMethod><ds:DigestValue>Zgx6vOvDg6tsbmulpLwmUtL0jPDtviPNK2WFy/GvZoY=</ds:DigestValue></xades:CertDigest><IssuerSerial><ds:X509IssuerName>CN=LB-LITAS-CA,OU=MSD,O=Lietuvos bankas,L=Vilnius,C=LT</ds:X509IssuerName><ds:X509SerialNumber>437264517056296634035879</ds:X509SerialNumber></IssuerSerial></xades:Cert></xades:SigningCertificate></xades:SignedSignatureProperties></xades:SignedProperties></xades:QualifyingProperties></ds:Object></ds:Signature></EDoc>
The part I am interested in particular is /EDoc/Signature/Object/QualifyingProperties/SignedProperties
Tried doing it with XPath
XPathExpression expr = xpath.compile("/EDoc/ds:Signature/ds:Object/xades:QualifyingProperties/xades:SignedProperties");
Node spNode = (Node) expr.evaluate(outdocp, XPathConstants.NODE);
but converting spNode to String and evaluating, it appears its missing namespaces
Ideally result should be
<xades:SignedProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" Id="xmldsig-d5d2b91d-f27c-4b8c-ab31-b4f9328c5194-signedprops"><xades:SignedSignatureProperties><xades:SigningTime>2024-05-26T16:52:45+03:00</xades:SigningTime><xades:SigningCertificate><xades:Cert><xades:CertDigest><ds:DigestMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></ds:DigestMethod><ds:DigestValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">Zgx6vOvDg6tsbmulpLwmUtL0jPDtviPNK2WFy/GvZoY=</ds:DigestValue></xades:CertDigest><IssuerSerial><ds:X509IssuerName xmlns:ds="http://www.w3.org/2000/09/xmldsig#">CN=LB-LITAS-CA,OU=MSD,O=Lietuvos bankas,L=Vilnius,C=LT</ds:X509IssuerName><ds:X509SerialNumber xmlns:ds="http://www.w3.org/2000/09/xmldsig#">437264517056296634035879</ds:X509SerialNumber></IssuerSerial></xades:Cert></xades:SigningCertificate></xades:SignedSignatureProperties></xades:SignedProperties>
happy yuan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.