I am trying to extract a subtree from XML document for canonicalization, but the subtree is missing namespace declarations for prefixed elements
Here’s a visualization of a subtree and namespaces which need to be in the result
Expected result should be this
<code><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>
</code>
<code><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>
</code>
<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>