response.writing out UTF8 XML. How?

I was having issues before with my XML being sent to the browser as UTF16. 
Via my XmlTextWriter, was able to fix this by explicitely setting the 
encoding to UTF8:

Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)

That fixed the issue.

I'm not generating an XML file using a different method grabbing XML from a 
DB and then reading it in as a stringreader, then transforming that via an 
XSLT file.

Eventually, I do the XSLT transformation and response.write the result to 
the browser.

The problem is that, once again, it's being set witn a UTF16 encoding.

I've tried to explicitely set the response encoding as such:

-------------
xslt.Transform(doc, xslArg, sw, Nothing)
Response.ContentType = "text/xml"
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.Write(sw.ToString)
Response.End()
-------------

But I STILL get the UTF16 declaration in my XML:

<?xml version="1.0" encoding="utf-16"?><rss version="2.0">...

Why!?

-Darrel 


0
7/17/2007 9:30:38 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
585 Views

Similar Articles

[PageSpeed] 53

darrel wrote:

> The problem is that, once again, it's being set witn a UTF16 encoding.
> 
> I've tried to explicitely set the response encoding as such:
> 
> -------------
> xslt.Transform(doc, xslArg, sw, Nothing)
> Response.ContentType = "text/xml"
> Response.ContentEncoding = System.Text.Encoding.UTF8
> Response.Write(sw.ToString)
> Response.End()
> -------------
> 
> But I STILL get the UTF16 declaration in my XML:
> 
> <?xml version="1.0" encoding="utf-16"?><rss version="2.0">...

Don't transform to a StringWriter, instead transform directly to 
Response.Output:
   Response.ContentType = "application/xml"
   xslt.Transform(doc, xslArg, Response.Output, Nothing)
And make sure your XSLT stylesheet has
   <xsl:output method="xml" encoding="UTF-8"/>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
7/18/2007 12:02:44 PM
> Don't transform to a StringWriter, instead transform directly to 
> Response.Output:

Aha!

So, I have this now:

Response.ContentType = "text/xml"
Response.ContentEncoding = System.Text.Encoding.UTF8
xslt.Transform(doc, xslArg, Response.Output, Nothing)
Response.End()

And that works! However, I've never epxlicitely put the <?xml...> tag in my 
XSLT. It seems that this is generated for me via the response output. Should 
I be explicitly including this in my XSLT file?

-Darrel 


0
7/18/2007 3:56:10 PM
darrel wrote:

> So, I have this now:
> 
> Response.ContentType = "text/xml"
> Response.ContentEncoding = System.Text.Encoding.UTF8
> xslt.Transform(doc, xslArg, Response.Output, Nothing)
> Response.End()
> 
> And that works! However, I've never epxlicitely put the <?xml...> tag in my 
> XSLT. It seems that this is generated for me via the response output. Should 
> I be explicitly including this in my XSLT file?

The XSLT document and its encoding are not related to the encoding of 
the XSLT result. An XSLT document is just an XML document and for an XML 
document the XML declaration (i.e. <?xml version="..." encoding="..."?>) 
is optional if the version is 1.0 and the encoding is UTF-8 or UTF-16.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
7/19/2007 3:46:31 PM
Reply:

Similar Artilces:

xml element names...
hi all, xml element names doesn't support names with whitespaces or symbol characters etc,... but is there any .NET class that can help convert these characters like hex form.... that is what XmlSchema does. Would hate to have to find these characters one at a time... thanks, System.Convert ? Or just do foreach(char Ch in ForbiddenChars) ClassName = ClassName.Replace(Ch,((int)Ch).ToString("X"));//You may have to cast the Ch to string, though that will convert a char to hex. "Maersa" <ma_ersa@hotmail.com> wrote in message news:eoScxcKwDHA.3428@TK2MSFTNGP11.ph...

Question Responses
Two Questions: 1. I have a program that is intended to run unattended. It runs, collects data and then closes all open workbooks. However, when it closes a workbook it asks "Do you want to save changes?". That requires an operator input. How do I avoid getting the question? 2. To start the process unattended I have to be in Excel. If my computer is on but Excel is not running, how do I get Excel open? Thanks for your help. Jim Walsh Hi, Q1. When you close the workbook use something along the lines of ActiveWorkbook.Close savechanges:=False or it it i...

Mapping a CSV file to an Xml Schema
Hi all, I am getting a CSV file like this from our client: "C1","2","12344","Mr","John","Chan","05/07/1976"......... I need to validate **each filed value** against a set of rules ,for instance for "05/07/1976" ,I need to make sure that it's in the right format ,It's not later than today and lots of other rules ,Is there somebody who can help me how to that?Can I map it to some sort of xml schema or something? Thanks for your help. Ali-R "Ali-R" <AliR@microsft.com> wrote in messa...

Two Servers Simultaneous Write Access to Fibre Channel
In a normal configuration, two Windows servers cannot both have write access to a fibre channel logical volume without potentially corrupting the volume. What are the *cheapest* options - using either standard Windows software or a third party file system - that would allow two Windows servers to simultaneously have write access to a single fibre channel volume? -- W Hi W, this will only be possible with some "art" of clustered file systems. There is currently only one from Microsoft available (CSV) which is free but currently ONLY for Hyper-V usage supported. ...

Regarding Reading XML Files in Visual C++6.0 using XMLDOMMethod.
Hi, While reading a 4.2 MB XML File in Visual C++ 6.0 using XMLDOM method, it is taking lot of time. But the same XML File when reading in Visual C# using Visual Studio 2005 is taking lesser time. How this Visual C++ 6.0 reading delay in XML can be avoided. ==========Suresh ...

Write to table then read data
On a form I have a command button with the following code. When clicked it copies the current forms data to a table and opens a form which has that copied data. First time thru it works fine, but when the record is edited and this button is clicked the data is not updated. I realise every time the buoon is clicked it writes new data to the table but how can I make it pull the most current data from the table? I don't want to over write the data in the table.. Do I need to give more information?? Suggestions?? stDocName = "frmLetterVals" lICCNNO = Me!ICNNo lID = Nz(DMax...

Conditional XML serialization???
Hi, I've got two classes - Entity which will have an array of Child objects in it and Child class. class Entity { public Child[] Children; } class Child { public string Name; public string Description; } I want to be able to serialize this class into two different XMLs. 1) looks like, <Entity> <Child Name="" Description=""/> <Child Name="" Description=""/> <Child Name="" Description=""/> </Entity> 2) looks like, <Entity> <Child Name="&quo...

webservice and using some kind of response to the client
Hello! When using ASP.NET(aspx page) I can use Respone.Write to send information to the browser.. I know that it would be better to use Windows-application event handle log but just for learning assume that I want to send ex.Message to the browser when an exception occur how can I do that. I tested to use Respone.Write but that was not possible ? [WebMethod] public decimal HowMuchWillItCost(string productName, int howMany) { SqlConnection sqlConn = null; try { ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["No...

Fail to response "save" or "save as " in Word 2007
I hope that someone out there can help me! I'm running Office 2007 with Windows XP. Everything was working just fine until the most recent Windows update just prior to this weekend. Over the weekend I began noticing a problem. In Word, when creating a new document or saving an existing document with a new name, I am unable to save or "save as". When I attempt to save or save as, I hear an error sound, but nothing appears on the screen - no dialogue box, nothing. The problem doesn't occur consistently. It happens more often than not, but not every time. If I...

How do I set up an out of office automated response?
The Out Of Office is available thru using the Exchange Server. If you are using an ISP use the following link for information on how to emulate the Out of Office rule. How to emulate the Out of Office Assistant in Outlook 2000 http://support.microsoft.com/?kbid=260987 How to emulate the Out of Office Assistant in Outlook 2000 that is installed with Internet Mail Only mode http://support.microsoft.com/?kbid=248830 Automatically reply to incoming messages with a POP3 or IMAP e-mail account http://office.microsoft.com/en-us/assistance/HA011223851033.aspx Nikki Peterson "angela"...

XML schema #2
I have a dtd file . I want that file transformed into schema .I found program dtd2xsd.pl but it only prints on standard output. Has anyone worked with that program and how to set some parameters so it can print into some file? mario410sPaM@yahoo.com remove spam from mail godfader wrote: > I have a dtd file . I want that file transformed into schema .I found > program dtd2xsd.pl but it only prints on standard output. > > Has anyone worked with that program and how to set some parameters so it can > print into some file? Hehe. Remember MSDOS commands? perl dtd2xsd.pl foo...

Handling multiple schemas and large files in XML
Hi I hope that this is the correct place to post this question. I'm looking at developing an application which will enable me to import and process some data that is made available to me as XML. One complication is that the providers of the data have published two different schema versions. Whilst effectively describing the same data, the 2nd schema is a significant refactoring of the first and so is almost totally different in structure. I also can't rule out the possibility that they will issue further versions too. I'd ideally like to be able to handle both of these schemas a...

Auto Response or Vacation Response
Does outlook have this function? I not can I get it and where? Out of Office works only if you connect to an Exchange server. Otherwise, you'll have to spoof it with rules - and this means leaving Outlook open & connected to the Internet for the duration of your absence. See http://www.slipstick.com/rules/index.htm M. Abell wrote: > Does outlook have this function? I not can I get it and > where? ...

Why no response
Don't mean to be rude, but could I have an answer to this question:(I have asked similar question before but no reply "Sometimes mail sits in the outbox and won't send. I have not altered any settings. I know it won't send if you go back into the email message and alter it(until you click send again) I don't think its due to any break in transmission as I have been able to access websites." hello i am a newbee so dont know if this will help,but i had the same problem a while back ,and i went to 'tools'send /recieve'..send and recieve all. it worked...

Save Excel File As XML
I'd like to "save as" from Excel to XML format. Works fine but there so much gibberish that gets exported when I try to use in Dreamweaver (Spry component), it only spits out gibberish. Anyone know how to work around this? Or to get Excel to spit out cleaner XML without any handcoding? Thnx, On 1/29/09 4:23 PM, in article C5A78889.9AD5%ronald.m.mochinski@nasa.gov, "Ron Mochinski" <ronald.m.mochinski@nasa.gov> wrote: > I'd like to "save as" from Excel to XML format. Works fine but there so much > gibberish that gets exported when I try to use...

removing xmlns form xml vb.net
Hello, If I have a xml document with a rootlevel <workOrderReleased xmlns="http://www.qad.com/qdoc" xmlns:enc="http://www.w3.org/2002/12/soap-encoding" xmlns:qcom="http://www.qad.com/qdoc/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="workOrderReleasedWithComments-JITS17_1.xsd"> When I use the following vb.net code to remove the xlmns attributes they all remove but the first one. I need to remove them all. objXMLDoc.Load(fileString) Dim objAttrib As XmlAttributeCollect...

Sending case acknowledgement to Responsible Contact
I am setting up a workflow to automatically send a confirmation email when a case is created. I am able to send an email to the Responsible Contact recorded on the cases, but need to edit the email template so that it is addressed to the first name of the Responsible Contact. At the moment I'm only able to use the first name of the primary contact for that account which obviously isn't suitable. Any help would be appreciated. I assume you are using CRM3, as this is no longer a problem in CRM4. We had the same problem, but as we are now on CRM4, but this is what I can remember ...

receipt templates
2 Questions: 1. I'd like to customize some templates but don't know where to start - Is there a Receipt Template/XML customization guide or equivalent that I could download? 2. My cash drawer is connected to my receipt printer and in order to open it I need to send the ascii string: 27,112,0,25,250 to the printer. Is there an xml command I could add to the receipt template that would write this out everytime a receipt is printed? Thanks in advance for your help!!! Check the reports library on Customer Source - IIRC, there is a receipt template that sends ascii commands to the p...

Embedd XML string within another XMl Document
Hi I am trying to build a XML db and within this I want to store an XML string as 1 element as "Info" below If I build up a XMLDocument with data - how can I transform it to a string containing &lt &gt so I can put it into my main XML document Thanks <?xml version="1.0" standalone="yes"?> <carsDS xmlns="http://www.tempuri.org/carsDS.xsd"> <CarScheduling> <AllDay>false</AllDay> <CarId>3</CarId> <Description>Wash this car in the garage</Description> <EndTime>2005...

Write XML File
Hi Can anyone help. I'm writing XML file using C# windows app. How can I code to achieve following structure in XML. <Report version="1.0" id="2003"> <Column name="Column1" system="System1" units="litres"></Column> </Report> Please help. Thanks. Regards Melson ...

Suggestions with Micrsosoft Response?
Well.. It's been a couple of weeks... if I am not mistaken... since this suggestion thing via the browser has come out... I was gonna say from A(xapta) to X(al) but it seems XAL is as popular as MBN... that people (partners and customers) have been posting suggestions... And curently it seems that there isn't one suggestion... that has a response from Microsoft? Where is the passion? Marc Wagner www.gmroii.net It is the potential man, not the product! lol. m t "Marc Wagner" <MarcWagner@discussions.microsoft.com> wrote in message news:285A938A-83C3-4F45-9...

How to learn to write macros
Hello All, Can someone tell me the links where i can learn how to write macros - i would prefer to do simple things with my macro such as copy information from several sheets to one sheet, find the average,sum..etc of cell values from different worksheets Here's one starting point - scroll down to the bottom of the sheet for VBA: http://www.datapigtechnologies.com/ExcelMain.htm Hope this helps. Pete On Apr 10, 3:06=A0pm, "Raveendiran RR" <ravi.gyang...@gmail.com> wrote: > Hello All, > > Can someone tell me the links where i can learn how to write macros...

Writing to .Ini file
Hi All, How to create the INI file and write to it? I know its similar to writing to registry. Some years back I have done that using BorlandC++ builder. Now I want to do the same with Windows API.Is there any MFC classes that help me to do that? Bootstrap my memory by giving some essentail function names if possible some snippet. Vinodh Kumar P Hi, Just call this function , this will also create the .ini file BOOL WritePrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpString, // string to add LPCTSTR lpFileName // initia...

Auto-response e-mail: Generate auto-response e-mail to
How to set-up next feature Auto-response e-mail: Generate auto-response e-mail to customer requests. (MS CRM Overview from MBS site) Ed I have not seen an auto-response feature in CRM. "ed" <anonymous@discussions.microsoft.com> wrote in message news:0bac01c3b4e3$2ca0d6e0$a101280a@phx.gbl... > How to set-up next feature > Auto-response e-mail: Generate auto-response e-mail to > customer requests. (MS CRM Overview from MBS site) > ...

evaluate marketing list members by campaign response
Is there an easy way to evaluate marketing list members by the campaign response they're linked to? P.e.: I have a campaign, with a marketing list attached to it. I already have 3 activities planned to distribute. To activity 1, I attach the full marketing list and distribute the activity. But before I distribute the following activity 2 I would first like to reevaluate the list, and only keep those members that have a registered campaign response with status interested to campaign activity 1. I already looked at the several options to update the marketing list, but there doesn't s...