sundeepgopal
asked on
Remove Version and encoding tag from xml using XSLT
Remove Version and encoding tag from xml using XSLT. Even though I have this code in the XSLT, It does not seem to get rid of the xml-declaration.
<xsl:output method="xml" indent="no" omit-xml-declaration="yes" />
Please help.
Thanks,
Sundeep.
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"
Please help.
Thanks,
Sundeep.
What processor are you using?
Do you have any template that copies a node? You may be reading in the processing instruction and copying it.
The starting part of your code would also help.
Do you have any template that copies a node? You may be reading in the processing instruction and copying it.
The starting part of your code would also help.
ASKER
I XML serialized an object in C#. Everytime I do that i end up with this
<?xml version="1.0" encoding="utf-16"?> , which i really want to get rid off. Is there any other way to get rid off it other than serializing the objects with utf-8 encoding?
<?xml version="1.0" encoding="utf-16"?> , which i really want to get rid off. Is there any other way to get rid off it other than serializing the objects with utf-8 encoding?
So, your C# is putting the encoding there, because of the encoding.
C# is fond of UTF-16.
If a document does not have an XML declaration, the encoding is defaulted to UTF-8
If you can't force the C# to serialise as UTF-8, it is impossible to drop the declaration, because someone has to tell the consumer of your data that the encoding is not UTF-8.
In short. If the encoding is not UTF-8, you NEED a declaration, full stop.
C# is fond of UTF-16.
If a document does not have an XML declaration, the encoding is defaulted to UTF-8
If you can't force the C# to serialise as UTF-8, it is impossible to drop the declaration, because someone has to tell the consumer of your data that the encoding is not UTF-8.
In short. If the encoding is not UTF-8, you NEED a declaration, full stop.
ASKER
I changed the xml format UTF-8 . Now i have a string XML showing
<?xml version="1.0" encoding="utf-8"?> but it is throwing XMLExeception saying "data at the root level 1 is invalid".
Any ideas?
<?xml version="1.0" encoding="utf-8"?> but it is throwing XMLExeception saying "data at the root level 1 is invalid".
Any ideas?
ASKER
I changed the xml format UTF-8 . Now i have a string XML showing
<?xml version="1.0" encoding="utf-8"?> but it is throwing XMLExeception saying "data at the root level 1 is invalid" when i try to XML read and do XSL transform.
Any ideas?
<?xml version="1.0" encoding="utf-8"?> but it is throwing XMLExeception saying "data at the root level 1 is invalid" when i try to XML read and do XSL transform.
Any ideas?
Maybe it is wise to force the encoding to be UTF-8 in the XSLT as well, in order to make sure that the XSLT result CAN be serialised as UTF-8 encoded (you migt get issues with the Byte Order MArk (BOM) if you start from a UTF-16 source
<xsl:output indent="no" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:output indent="no" omit-xml-declaration="yes"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The issue is after serializing i get a "." infront of the <?xml version="1.0" encoding="utf-8 ?> there is some problem with the that . Here is the eroor when i try to load that string to xml document
System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderIm pl.Throw(E xception e)
at System.Xml.XmlTextReaderIm pl.Throw(S tring res, String arg)
at System.Xml.XmlTextReaderIm pl.ParseRo otLevelWhi tespace()
at System.Xml.XmlTextReaderIm pl.ParseDo cumentCont ent()
at System.Xml.XmlTextReaderIm pl.Read()
at System.Xml.XmlLoader.Load( XmlDocumen t doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Loa d(XmlReade r reader)
at System.Xml.XmlDocument.Loa dXml(Strin g xml)
System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderIm
at System.Xml.XmlTextReaderIm
at System.Xml.XmlTextReaderIm
at System.Xml.XmlTextReaderIm
at System.Xml.XmlTextReaderIm
at System.Xml.XmlLoader.Load(
at System.Xml.XmlDocument.Loa
at System.Xml.XmlDocument.Loa
But it could be that the serialisation takes place in the architecture you wrapped around the XSLT process.
How do you execute the XSLT process?
I assume that the serialisation process outside the XSLT feels a need to explicitely output the declaration, because it encounters some issues with the encoding, or simply because it always does.
Note that you can only leave the encoding out if the XML is to be serialised with an UTF-8 encoding