Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2004, 06:12 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default encoding="utf-16" Problem

Can anyone tell me why when I transform some XML using XSL the transformed XML has <?xml version="1.0" encoding="utf-16"?> as the header?

I cannot open this in my browser? Why are there different encodings in XML?

Thanks for any comments.

 
Old September 8th, 2004, 07:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can change this with the encoding attribute of the xsl:output tag.

Maybe if you tell us what platform is being used for your transforms then we can tell you why you get utf-16.

The concept of encoding isn't limited to XML. Different encodings exist for internationalisation purposes - US ASCII isn't much use in many places around the world.
 
Old September 8th, 2004, 07:04 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Depends on how you transformed it. The encoding is needed so applications can determine how to read the file. Very surprised IE can't cope, what error are you receiving? If it's cannot switch encoding etc. then your serialisation process is suspect.



--

Joe (Co-author Beginning XML, 3rd edition)
 
Old September 8th, 2004, 08:04 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the comments.

I transformed it in a vb.net project using the following code;

Dim xmlToTransform As New Xml.XmlDocument
Dim XSLTransform As New Xml.Xsl.XslTransform
Dim transformedXML As New Xml.XmlDocument
Dim XSLfilepath As String
XSLfilepath = XSLFileTextBox.Text
Dim sw As New StringWriter

xmlToTransform.Load(XMLFileTextBox.Text)
XSLTransform.Load(XSLfilepath)
XSLTransform.Transform(xmlToTransform, Nothing, sw, Nothing)

My XSL is declared as follows:

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:scripts="urn:my-scripts" exclude-result-prefixes="msxsl scripts">

I specified encoding="utf-8" in my XML and XSL. Why does it return encoding="utf-16" when it is transformed?

The error I get when trying to open the new XML in IE is:

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
---------------------------------------------------------------------
Switch from current encoding to specified encoding not supported. Error processing resource



 
Old September 8th, 2004, 11:03 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Try using XmlTextWriter instead of stringwriter and setting the encoding:
Code:
XmlWriter xtw = new XmlTextWriter("pathToXml.xml", Encoding.UTF8);
Unfortunately I've got to do some of the work I get paid for, I'll try to post a full example later.



--

Joe (Co-author Beginning XML, 3rd edition)
 
Old September 9th, 2004, 04:07 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe.
I've replaced it with the code that you suggested and it does work.

Dim xtw As XmlWriter = New XmlTextWriter(pathToWriteXML, System.Text.Encoding.UTF8)
XSLTransform.Transform(xmlToTransform, Nothing, xtw, Nothing)

It seems a bit of a bizarre way of doing things though. I don't really want to have to write the XML to a file every time, ideally i'd have it in a domXML object so that I can process it further.

Do you know of any other objects in vb.net that would do this?

 
Old September 9th, 2004, 07:50 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've cracked it!

Load the output from the transform into a MemoryStream and then use a StreamReader.ReadToEnd() object which can return a string and you can load this into a domXML object.

Job done!


 
Old April 10th, 2015, 02:23 AM
Registered User
 
Join Date: Apr 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%)

Hi Programmers,

I have a problem in drop down box, i am getting below exception when i am trying to display special characters (%, < , >) in a jsp, i am sending these values from java class which is stored in the data base.. can anyone help me out to fix this?


java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " o"




thanks in advance.





Similar Threads
Thread Thread Starter Forum Replies Last Post
CDO.Message utf-8 Problem hellsa Classic ASP Professional 2 June 28th, 2009 11:02 PM
encoding="UTF-8" Pankaj C XSLT 3 October 4th, 2007 05:27 PM
Encoding problem. Neal XML 0 April 4th, 2006 06:49 AM
JSP encoding problem recepkocur Apache Tomcat 0 December 3rd, 2004 02:44 AM
UTF-16 dkb XML 14 November 7th, 2003 09:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.