greddin
asked on
Set ContentType to text/xml with Javascript
Hi: I have the following Javascript function that's working but only writing the data out as a regular webpage. How do I set the content type to "text/xml" so that it displays as a real xml file?
function openRSS() {
//var html = '';
var str = '<?xml version=""1.0"" ?>\n';
str += '<rss version="2.0">\n';
str += '<channel>\n';
//str += '<title></title>\n';
//str += '<link></link>\n';
str += '<description>CNIC News</description>\n';
str += '<language>en-us</language >\n';
var showTextElem = document.getElementById("t xtDiv");
if (showTextElem != null) {
str += showTextElem.innerHTML;
}
else
{
alert("Could not find the text section in the HTML!");
return;
}
//html += '\n</bo' + 'dy>\n</ht' + 'ml>';
str += '</channel>\n';
str += '</rss>\n';
var textWin = window.open("","rss");
textWin.document.open();
textWin.document.write(str );
textWin.document.close();
}
function openRSS() {
//var html = '';
var str = '<?xml version=""1.0"" ?>\n';
str += '<rss version="2.0">\n';
str += '<channel>\n';
//str += '<title></title>\n';
//str += '<link></link>\n';
str += '<description>CNIC News</description>\n';
str += '<language>en-us</language
var showTextElem = document.getElementById("t
if (showTextElem != null) {
str += showTextElem.innerHTML;
}
else
{
alert("Could not find the text section in the HTML!");
return;
}
//html += '\n</bo' + 'dy>\n</ht' + 'ml>';
str += '</channel>\n';
str += '</rss>\n';
var textWin = window.open("","rss");
textWin.document.open();
textWin.document.write(str
textWin.document.close();
}
I don't think the content-type can be changed after the fact. If the file starts off as html, you can't just change it to xml.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set the content type in your original page. Like if you are using JSP then you can set the content type by using page directive as:
<%@ page language="java" contentType="text/xml; charset=UTF-8" %>
<%@ page language="java" contentType="text/xml; charset=UTF-8" %>
You can also replace < with > --> I meant: You can also replace > with >
Or simply use meta tag as:
<meta http-equiv="Content-Type" content="text/xml; charset="utf-8" />
<meta http-equiv="Content-Type" content="text/xml; charset="utf-8" />
Re: meta tags
Meta tags don't affect the output here in IE 6 (I tried it, no luck)....
Meta tags don't affect the output here in IE 6 (I tried it, no luck)....
Has it ever been determined why you'd want to open a popup with an rss xml feed in it?