While transforming XML to XML using XSLT I have included doctype in output XML. But a line break is created in the output XML doctype declaration.
XSLT:
<xsl:output method="xml" doctype-system="book3.dtd" doctype-public="-//Atypon//DTD test//EN" version="1.0" encoding="UTF-8" indent="no"/>
output XML after using XSLT:
<!DOCTYPE book
PUBLIC "-//Atypon//DTD test//EN" "book3.dtd">
Space and line break are created in between book and public in doctype declaration.
I need the doctype declaration in a single line.
Can anyone help me to do this?
When you say you "need" it to be on one line, this means that you must be processing the resulting XML using a parser that attaches significance to things (like ignorable whitespace) that should be considered insignficant.
The correct solution to your problem is to process XML only with conformant XML parsers, then you won't need to try and tweak the serialized format to fit with the restrictions your non-conformant parser imposes.
However, the Saxon serializer is designed to be customized if you really have to. Call
Configuration.setSerializerFactory()
to register a subclass ofSerializerFactory
which overrides thenewXMLEmitter()
method to create a subclass ofXMLEmitter
, and in your subclass ofXMLEmitter
, override thewriteDocType()
method to format the DOCTYPE declaration in the way you want it.