2010-11-28 8 views
4

私は、出力XMLに次のコードを建て:IEが自分の出力をXMLとして認識しないのはなぜですか?

public static XDocument Serialize<T>(this T source) where T : class 
    { 
     XDocument document = new XDocument(); 
     XmlReflectionImporter xmlReflection = new XmlReflectionImporter(); 
     XmlTypeMapping xmlMapping = xmlReflection.ImportTypeMapping(typeof(T)); 
     XmlSerializer xmlSerializer = new XmlSerializer(xmlMapping); 

     using (XmlWriter xmlWriter = document.CreateWriter()) 
      xmlSerializer.Serialize(xmlWriter, source); 

     return document; 
    } 

その後、私のASPXページの一つで、私は次の出力があります。

XDocument output = GetSomeXmlSerializedOutput(); 
    output.Save(Response.OutputStream); 


GetSomeXmlSerializedOutput()は、基本的には、給紙から出力され、クラスをSerialize拡張メソッドに追加します。

ページのヘッダーは次のようになります。

<%@ Page Language="C#" CodeBehind="Alerts.aspx.cs" Inherits="Infinix.Diageo.WebApp.Get.Alerts" ContentType="text/xml" %> 

Firefoxが正しく出力がXMLであることだけContentTypeをから想定しています。 IEはそうではありません。参考のために、出力XMLは次のようになります。

<?xml version="1.0" encoding="utf-8"?> 
<ALERTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <ALERT> 
    <ID>1</ID> 
    <TYPE>ALERT</TYPE> 
    <NAME>neim</NAME> 
    <DETAIL>diteil</DETAIL> 
    <DATE>11/28/2010</DATE>  
    <TIME>13:50:02</TIME> 
    </ALERT> 
    <ALERT> 
    <ID>2</ID> 
    <TYPE>EVENT</TYPE> 
    <NAME>iven</NAME> 
    <DETAIL>ditel</DETAIL>  
    <DATE>11/28/2010</DATE> 
    <TIME>13:50:15</TIME> 
    </ALERT> 
    <ALERT> 
    <ID>3</ID> 
    <TYPE>BIRTHDAY</TYPE> 
    <NAME>pijazo</NAME>  
    <DETAIL>grande!</DETAIL> 
    <DATE>11/28/2010</DATE> 
    <TIME>13:50:23</TIME> 
    </ALERT> 
</ALERTS> 

IEはこの出力を本物のXMLとして認識しません。

+0

'application/xml'? – khachik

+2

神様、ありがとう、これは私を夢中にさせていた。私はあなたにいくつかの担当者を授けることができるように答えとして投稿:) – bevacqua

答えて

3

ページの指示文にContentType="application/xml"を設定する必要があります。

<%@ Page Language="C#" CodeBehind="Alerts.aspx.cs" 
    Inherits="Infinix.Diageo.WebApp.Get.Alerts" ContentType="application/xml" %> 
関連する問題