I’m using Java’s Transformer class to process an XML Document object.
This is the code that creates the Transformer:
import javax.xml.transform.TransformerFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, 'no'); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, 'yes'); transformer.transform(source, result);
Currently, my output looks like this: <svg … />. I’d like it to include the namespace of each element, as in <svg:svg … />
How can I do that ?
Note that
<svg xmlns='SVGNS' />is the same as<svg:svg xmlns:svg='SVGNS' />.Did you check you called
setNamespaceAware(true)on yourDocumentBuilderFactoryinstance ?