public String toXmlString ( ) throws TransformerException { if ( doc == null ) { return null ; } final DOMSource domSource = new DOMSource ( doc ) ; final StringWriter writer = new StringWriter ( ) ; final StreamResult result = new StreamResult ( writer ) ; final TransformerFactory tf = TransformerFactory . newInstance ( ) ; tf . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; final Transformer transformer = tf . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . ENCODING , StandardCharsets . UTF_8 . name ( ) ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; transformer . setOutputProperty ( OutputKeys . DOCTYPE_PUBLIC , "yes" ) ; transformer . setOutputProperty ( "{http://xml.apache.org/xslt}indent-amount" , "4" ) ; transformer . transform ( domSource , result ) ; return writer . toString ( ) ; }
Creates a text representation of a CycloneDX BoM Document .