0
votes

I am facing issue with XML Declaration. I want to omit XML declaration from XML file.For that I have written below code in XSLT file.

<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8"/>

Output file generated successfully without XML declaration.Now when I manually copy that file to another location and open it below xml tag is getting added at the top of the file.

<?xml version="1.0"?/>

I don't want above tag in my xml file.How can I prevent it.

1
It could be your browser that's adding it when it's displaying the XML. - Lingamurthy CS
Yes.Only IE add xml declaration tag.in FF and Chrome no xml declaration tag. Thanks. - Mahesh Chitroda
I just tested it with Saxon-B XSLT processor. The directive omit-xml-declaration="yes" works as advertised. If it's not working, the implementation of your XSLT processor must be incomplete. For example, the implementation of the FireFox XSLT 1.0 processor lacks the implementation of disable-output-escaping. If the implementation is not there, your only solution would be to use another XSLT processor. - zx485
Is MSIE adding it when rendering the XML instance file you created without the declaration, or is MSIE adding it when you try to run the XSLT using MSIE? Either way, seems like an issue with MSIE. - Dan Field

1 Answers

0
votes

Seeing the comments above suggests that the problem was indentified to be caused by MSIE.

I'm adding an answer here in case somebody else hits similar problem and needs to debug the issue. The important parts of your question:

Output file generated successfully without XML declaration.

Okay, so you have a file that has correct bytes in it.

Now when I manually copy that file to another location [...]

I'm assuming you know how to copy a file so you will have exactly the same bytes in in the copy.

[...] and open it below xml tag is getting added at the top of the file.

This sounds really weird unless the software that you use to open the file has major brain damage. Just opening a file should never ever modify it.

However, some software is known to have major brain damage. Well known examples include Microsoft Word, Microsoft Visio and Microsoft Internet Explorer. (I'm noticing a common vendor here ;)

To be exact, MSIE probably does not modify the actual file on disk (unlike Word and Visio) but just display something else but the actual contents of the XML file.