I can successful remove namespace prefixes from all elements, but would just like to remove prefixes from specific elements
I would like to remove the namespace prefix from the X509Data element:
<?xml version="1.0" encoding="UTF-8"?>
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
</xenc:EncryptedKey>
<ds:X509Data>
<ds:X509Certificate>AAA=</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
to:
<?xml version="1.0" encoding="UTF-8"?>
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
</xenc:EncryptedKey>
<X509Data>
<ds:X509Certificate>AAA=</ds:X509Certificate>
</X509Data>
</ds:KeyInfo>
Java code:
public class TestXmlTransformer {
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException,
TransformerFactoryConfigurationError, TransformerException {
InputStream xmlData = new FileInputStream("C:\\Users\\xxxxxx\\Desktop\\spoon\\test1.xml");
Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlData);
Source stylesource = new StreamSource("C:\\Users\\xxxxxx\\Desktop\\spoon\\test1.xsl");
Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesource);
StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(xmlDocument), new StreamResult(stringWriter));
System.out.print(stringWriter.toString());
}
}